It traces back to an assumption made during Sonic's creation. Yuji Naka has since acknowledged it as a mistake — the team designed the character on the belief that hedgehogs could not swim.
The trait stuck anyway and became one of the most recognisable parts of the character, which is a good reminder of how often a design accident turns into canon.