There is no actual hiding mechanic, you just hide by getting under tables, hiding in closets, hiding behind different obstacles or in plants.
Looks like he found you because he was just inspecting the room and saw you or you got unlucky enough to be at exact location he was going towards.