Hello,
To lock/unlock JTAG you simply follow the reference manual:

In case you want to unlock it via SW, then I suggest you to prepare routine to get Censorship into default state in your application in advance or you can always change it via JTAG access if password is known.
Best regards,
Peter