When Winston secretly begins his diary, he thinks about the likely consequences of doing so (this is very early in Chapter 1).

He knows that keeping a diary is not illegal. The reason for that is that there are no laws in Oceania so nothing is actually illegal. The point of that is that laws would require the government to follow them. If there are no laws, the government can do whatever it wants.

Even though keeping the diary is not illegal, Winston knows that it will probably get him executed. At the very least, he expects, he'll get sentenced to 25 years at hard labor if he's caught.