This phrase is casual and more commonly used in spoken rather than formal written English. Sure, you can wear pajamas to the store—there's no law against it.
Pro Tip 2/3
Implicit Approval
Using the phrase can suggest that an action, while not illegal, may still be frowned upon. He double-dips his chips, and while there's no law against that, people find it gross.
Pro Tip 3/3
Sarcastic Tone
Can be used sarcastically to imply that something is permissible but not necessarily wise or considerate. There's no law against eating smelly food on the bus, but you'll make enemies.