On the outside, we say, "wow, those were really strong men of God to sing in prison!"
But really, if you were in prison, even if you were like Billy Graham, would you feel like singing? I mean, when on an average day do you break out in song and dance anyway? (ok, sometimes I do nowadays, but that's beyond the point)
Maybe they started singing not because they were happy, but in order to make themselves happy, or more importantly, to focus themselves back on the reason they were in jail and take strength from those facts.
Hm? Conclusion?
We don't have to sing just when we're happy. Sing to because in point of cold fact, God is real and we need to be reminded of that every now and then.
(You might also sing as a coldly logical proclamation of Gods amazingness, like preaching.)