The only thing that would be "illegal" about someone's use of the Holodeck would be if they somehow violated the safety or privacy protocols without the proper authorization. The Holodeck is definitely capable of creating lethal situations, and it requires the permission of multiple senior officers to bypass the safety systems.
If someone somehow "hacked" the Holodeck to bypass the safety systems without the proper permissions, that would probably be a no-no, especially since some of the possible uses for doing so would be quite sinister indeed (such as leaving the systems disabled, giving the next person who loaded up a swordfighting program a literal fight for their lives). By the same token, the Holodeck is controlled by the ship's computer, which has access to all the ship's data, and if someone got around security using the Holodeck to access confidential information, that's generally frowned on too.
Other than that, there seems to be a certain amount of privacy expected and given for most uses of the Holodeck. The command staff can, if they think it's necessary, bypass most security features of the ship, including unlocking doors, viewing personal logs, and loading private Holodeck programs. But, they only do so if there is suspicion about the person's mental state; for the most part, they leave well enough alone. As TNG is at best a PG show, it obviously doesn't go too deeply into the racier things you could do with a Holodeck, but just because humans have done away with greed doesn't mean they've abandoned ALL their baser instincts.
Pathfinder
episode. Something which admiral Paris disapproved of ("I understand that you have been spending time with a holographic recreation of my son, among others. Frankly, I find that rather disturbing."), but which IIRC had no serious consequences for him in and of itself. His excessive Holodeck use and refusal to accept counseling for that was cited as a reason for temporarily removing Barclay from the Pathfinder project, however.