As long as you are not trespassing or sneak-peeking on private property, it is not illegal to look through someone's window, provided that you are on public property or are looking into your building. But sneak peeking on private property is considered an offense. Apart from this whole legal and illegal debate, it would be unethical to look through someone's window and breach their privacy if we consider the moral grounds.