When the light rays from a light source enters the hole of pin hole camera it goes in a straight line so when it enters the top becomes bottom and bottom becomes top. So the image is inverted
You can figure out why an image in a pinhole camera is upside down if you think about how the light travels to get to the image. Light from an object higher (or the top of the object) than the camera...