Well, yes, you were rude. So was Roomie. One does not cancel or justify the other.
It's possible to be polite, even when in pain. Even when in shocking, startled pain. Even when in prolonged, chronic pain.
At this point, apologizing for your part in it would be appropriate. A quick, "I'm sorry I reacted rudely. I should not have shouted at you and called you insulting names." and then leaving it, could provide an open door for Roomie to say an "I'm sorry", too. It might not.
Either way, shouting and screaming at someone in another room is rude. You did have the option to stay mute, respond with a pinched and quiet, "Slammed my finger" when Roomie came into the room, or to just not scream back at Roomie.
Pain does not justify ugly behavior, in my opinion. It's still possible to maintain a bit of politeness. People do it every day.