Why do Markarth guards attack me after I left Calcelmo's lab?
Okay, in my fifth run through Calcelmos lab I finally found the reason.
Just in the second room (you enter the lab, go a bit further, turn right and go further) there is one Wizard Guard and, sadly, a normal Markarth City Guard. When it locates you, it places a bounty worth 5 on you (probably because you shouldn't be there).
When you talk to him and try to pay him to strike out the bounty you will be teleported out of the lab. Luckily the bounty is so small that you can convince him it's too much work to cope with you and he just leaves you alone.
After not killing this guard, I could have the bounty removed on any other city guard after leaving the lab and the other city guards won't be hostile.
While I'm uncertain why the guards are hostile -- I usually just break in -- there is an easier way out. It is possible, I guess, that killing one of the city guards who entered the room with the Falmer transcription set off the guards in the museum, although I don't know exactly what's happened.
Anyway, once you get the transcription, just jump down the waterfall on the Wizard's Balcony (which has a quest marker, so it's the intended exit route).
There is a blade trap in the room where the Markarth guard is, activated by a pull handle on the wall.I activated the trap, the trap killed the Markarth guard, and voila! no arrest, no bounty.