Keep in mind that the 5-foot squares are an abstraction. Per PHB p. 191:
Space: A creature's space is the area in feet that it effectively controls in combat, not an expression of its physical dimensions. A typical Medium creature isn't 5 feet wide, for example, but it does control a space that wide.
So you can be grappling (not so much wrestling on the ground as grabbing at each other's arms from a standing position) at the shared edge of your respective 5-foot squares and still have a certain influence over the rest of the area. You aren't literally 5 feet away from each other, but you are in "different squares" which, in a game where distance is measured only in 5' increments, makes you effectively 5 feet away. It's about the same distance you'd be for an unarmed or dagger strike, also notionally performed "from five feet away." There are systems like GURPS where grappling involves moving into the same space, but DND isn't quite that granular about space.