Sonic's inability to swim is a long-running quirk of the series. According to one playful take, the very first time Sonic went into the water, the things on his arms popped out and he nearly sank, until his mum pulled him out.
Whatever the real reason, it is become a running joke among fans. Maybe Sonic should finally sign up for swimming lessons! In the meantime, players just have to keep him out of deep water.