Sure it's legal. You'll find photocells mounted on lots of things that already penetrate the rooftop. Makes good sense. On RTU's is a popular place to find a photocell mounted. Doesn't make the troubleshooting process any easier, so I like to make a note on the panelboard cover when I find these things for the next guy.