It really wasn't. They captured you because you were nearby, that's all. Even when they became aware that you had no connection to Ulfric or his soldiers and they had absolutely no reason at all to execute you they still went ahead with it.
It's not: "Oh, sorry, we thought you were with the enemy." It's: "Who are you? Whatever, kill him as well."
The Empire saved Skyrim selflessly from the Thalmor during the Great War
The Empire did win the war... with an army of Nords from Skyrim. The Empire got its arse utterly torn open by the Thalmor, losing Cyrodiil and the the Imperial City for over a year. They were only able to take it back because the emperor fled to Skyrim and recruited local Nords to fight for him. Thousands of Nords died to reclaim the Imperial City, and their reward was the fundamental defilement of a cultural icon.
This wasn't "selflessly" saving Skyrim. Skyrim saved Skyrim in that war, it just did so under an Imperial banner.
That said...
The Stormcloaks are led by a man whose only interest is becoming the High King of Skyrim. For all his rhetoric, Ulfric's goal is to simply be the Big Chief, which he achieves through defeating his enemies and replacing them with sycophants. Every Jarl appointed by Ulfric is given the title simply because they have agreed to vote for him when he calls a moot, not because of their deeds or suitability to the position. The whole civil war is a power grab by a man too cowardly and unliked to take it legitimatley. This is best demonstrated by his killing of the previous High King, Torygg. Nord culture values honour in combat, but Ulfric's use of the Thu'um in their duel displays his lack of honour. Every eyewitness to the duel agrees that Ulfric killed Torygg with the Thu'um directly, but Ulfric says he used it to sudbue Torygg and then finished him with a sword. Ulfric is the only one with a reason to lie about this, and his hasty retreat from Solitude lends credence to his dishonourable actions and weight to the accusations of murder. Ulfric just wants power, and he goes against the values of his own people to get it.
In addition to fighting a devastating civil war for petty, personal reasons, Ulfric (and his supporters) are enormously prejudiced and xenophobic. Windhelm, the city Ulfric directly rules as Jarl, is the only city in all of Skyrim that actively bars Khajiit and Argonians from entering the city walls. The city's Dunmer population are restricted to a ghetto (with the racial moniker "Grey Quater" no less). Ulfric and his Stormcloaks openly and often talk about how "Skyrim belongs to the Nords" and how those who side with the Empire are not "true" Nords. His whole idealogical position is built on racism and national purity, which is as pragmatically short-sighted as it is morally bankrupt. He even despises the Reachmen, Bretons who, like Ulfric, rose up to reclaim their native homeland only to be put down by the sword. Ulfric's sword. I could go further with regard to how Tamriel itself is not a native home for any human races and Nords are, technically speaking, foreigners to the lands they claim as their own, but the point is made: Ulfric either despises or doesn't concern himself with anyone who isn't of the same racial or political type as himself.
These facts alone are enough to ensure that I won't side with the Stormcloaks and view those who would in a less-than-favourable light. The Empire is the better choice on every level, in my view. The Empire is a monarchical power structure with large amounts of of decentrealised authority. People from any race and background can occupy the highest official positions. With a few notable exceptions, religious freedom is almost universally guaranteed. The Empire has brought prosperity and, until the end of the Third Era, security to the continent. In the wider picture, the Empire is one of the only obstacles to the Thalmor achieving their ultimate goal (which is the destruction or subjugation of all humankind and a return to the Merethic Era, the "Era of Elves"). The only thing working against the Empire, in my view, is their ridiculous decision to execute you for literally no reason. If you can overlook that, then there's only one clear faction to side with. If you can't, side with no one as they're both a bunch of bastards.