There is a more than thousand years old general mannerism rules when you visit temples and shrines in Japan. We have kept such as daily customery rules in this country . No, there is no legal boundary, but if you are sensible and intelligent adult, I believe you'd understand.