They assumed he was a Stormcloak spy.
As to how they knew his name? Well...I have no idea. They could've compiled a list, but it would have been sloppy work when they apparently miss Dragonborn and don't bother demanding his/her name.
As for Ulfric, remember that Stormcloak dude who walked forward in the middle of the priest's sermon? They decided to oblige him by skipping the last rites and proceed with the execution. Of course, after that, they should've gone after Ulfric, not us.
How did they know Lokir's name and village? Isn't it obvious? They already asked him. Why did they not know your name yet? That's obvious too. What's the first line of the game?
"Hey you, you're finally awake."
They can't ask you, if you're unconscious, and no one else seems to know who you are.