Is this sentence grammatically correct?

You ask whether the sentences are "grammatically correct" - which they are.
But, to me, they do not (necessarily) mean the same thing:

He swung his legs, and [then] sang a song.

Although both parts of the sentence are in the simple past tense, it is not clear from your wording whether the two actions were sequential or simultaneous.

He swung his legs, [while] singing a song.

Here, the first part of the sentence is in the simple past tense, but the second part is in a continuous tense and it is clear that the two actions were simultaneous.

So in summary:

  • Yes, they are both "grammatically correct".
  • But, the first sentence is ambiguous as to whether the two actions were sequential or simultaneous.
  • In the second sentence, the two actions were clearly simultaneous.

"He swung his legs, and sang a song."

Tense-wise, this is correct. But, it does't need a comma. Your "and" sufficiently links the two clauses. If he was doing more than just swinging his legs you would insert a comma to list his actions. Such as:

"He swung his legs, waving his arms and singing a song."

"He swung his legs, singing a song."

This sentence is correct. Yes, your comma takes the place of your "and was". There is no disagreement between your participles.