It took many idiots.
In short, Maryland got the land north of the southern bank of the Potomac and south of the 40th parallel. Surveying was pretty crude then, hence the importance of the Mason-Dixon Line.
So the boundary is weird because:
Maryland includes most of the Chesapeake Bay. And a lot of what is shown as land there is actually tidal wetlands. A few decades ago the state stole the wetlands from the actual owners.
The Potomac flows where it flows, adding the weird southern boundary.
There was a fight over Delaware. Maryland lost, hence the missing eastern corner.
There was a fight over the Eastern Shore. The Calvert-Scarborough Line resulted in two Virginia counties on the east side of the Chesapeake Bay.