Tie balloons together at their knots and they push each other into the most spread-out arrangement they can: two point in opposite directions, three form a flat triangle, four point to the corners of a tetrahedron. Electron pairs around a central atom do the same, because they all carry negative charge and repel each other. That is VSEPR theory, and it predicts the angles: 180° for 2 domains, 120° for 3, 109.5° for 4.
A domain is any region of electrons around the central atom: a single bond, a double or triple bond (each counts as one), or a lone pair. Methane, CH4, has 4 bonding domains, so it is tetrahedral with 109.5° angles. Ammonia, NH3, has 3 bonds and 1 lone pair: the electron pairs are still arranged tetrahedrally, but you see only the atoms, so the shape is trigonal pyramidal. Water has 2 bonds and 2 lone pairs, so it is bent.
Electron geometry and molecular geometry are different answers. Electron geometry includes the lone pairs; molecular geometry names only where the atoms are. Lone pairs also crowd harder than bonding pairs, squeezing the angles: 109.5° in CH4, 107° in NH3, 104.5° in H2O, with one more lone pair each time. So two attached atoms do not guarantee a straight molecule; check the central atom for lone pairs first.
Think of it like this. Electron domains around a central atom behave like passengers in a crowded elevator, each moving as far from the others as the space allows. A lone pair is a passenger with a big backpack: it takes up more room and squeezes the others closer together, but it doesn't show up in a photo of the atoms.
Core idea. Electron domains around a central atom repel and spread as far apart as possible; the positions of the atoms in that arrangement, with lone pairs present but unseen, give the molecule's shape and bond angles.