It is not illegal to drive around with a hitch in.
You can legally drive around with your hitch inside your receiver hitch on the vehicle as there are no laws that state you must remove the hitch when not towing.
I always leave my hitch in whether I'm towing or not but I do remove it occasionally and spray it with a bit of lubricant or it could get stuck.
If you do leave your receiver hitch in though it's best to use a locking pin or they can sometimes become stolen.
If you got pulled over and the cop said it was illegal to leave the hitch in it could be a city law and not an actual state law.
I've heard that it could be illegal in some places to leave the hitch in but I've never came across any actual laws that state you can't drive around with a hitch in.