New main objective (Forsworn): Return to Madanach
Report to the King in Rags and you will learn that the rebel has a plan of escaping the prison. It's been far too long that he dwells here, while his companions suffer on the surface. If you manage to prove your loyalty to him, he will let you go with him.
In order to gain Madanach's trust, you will have to kill Grisvar the Unlucky. His name fits perfectly - he's not guilty of anything and will only serve as a way of proving your loyalty. In the end he will give you a Shiv - you can use it either on him or Grisvar. Remember that you can still back out of supporting the rebels - you just need to kill Madanach.
New main objective (Forsworn): Kill Grisvar the Unlucky
You can take care of Grisvar in one of two ways. If you tell him that Madanach is sending his regards, the desperate miner will jump at you and try to run away. You can catch him and kill him in this case. The second solution is cruel as well: you can sneak up to him from behind and kill without saying a word.
After killing him, you can return to Madanach. He has recognized your loyalty, so you can join the Forsworn rebel in the mine.
New main objective (Forsworn): Return to Madanach
New main objective (Forsworn): Follow Madanach
Return to the King in Rags. He will be happy that you have completed the mission and will tell you to follow him. Inside the cave in the middle of the mine, all the prisoners intrigued by what you have done to Grisvar have gathered. Undiscouraged Madanach will explain that he has found a tunnel inside his cell, leading into dwarven ruins and further to Markarth. The prisoners will grab their weapons and follow the leader into the Dwemer catacombs. You have to be among them.
Follow the prisoners, and you will have to deal with a couple Frostbite Spiders and Dwarven Spheres. You don't have to worry however - you will defeat them thanks to numerical superiority and Madanach's spells. As you reach the gates of Markarth, you will meet a woman who will give you back your equipment and also a Forsworn armor. At this points all that's left is to leave the ruins and fight with the Nords awaiting outside.
The decisive battle begins now. The Forsworn who escaped the Cidhna Mine will have no mercy for the Nords of Markarth. During the massacre that will spread through the street, all city guards and Thonar Silver-Blood will die. Afterwards the refugees will run from the city and settle at Druadach Redobut. It's the only place in Skyrim where Forsworn will greet you with open hands.
New main objective (Nords): Kill Madanach
If you decide to attack the King in Rags, it will mean supporting the Nords. Fighting the old man isn't easy, as he can use a couple nasty spells (you're in a bad position if you're not playing as a mage). In order to make up for it, equip a weapon - either two pickaxes or the Shiv (Talk to Grisvar about getting a Shiv). The fight will be much easier if you can use a weapon.
Don't let Madanach run from his cell and alert the other prisoners - otherwise they will support him and massacre you. If you manage to finish him off silently, search his body and take everything you find beside him.
New main objective (Nords): Search Madanach's body
New main objective (Nords): Read Madanach's note
After killing the King in Rags, you have no other choice but to run from the prison, as the other prisoners are in fact Forsworn, who won't be happy about the death of their leader. That's why you should quickly search his body and take his Key and Note.
From the note left by Madanach you will learn that he was planning to run from the prison and the key that you have found leads to an ancient tunnel leading straight to Markarth. All that's left now is leaving the unfriendly caves.
New main objective (Nords): Escape Cidhna Mine
Be very cautious after reaching the dwarven structure. You will have to face a couple Frostbite Spiders, with your only weapon being pickaxes or the Shiv. If you want to avoid fighting them, you can try to quietly sneak past.
A much greater challenge awaits you in the further part of the ruins. The large room is guarded by Dwemer Spheres, or even a Centurion if you're playing a high-level character! You definitely shouldn't try fighting them - they're very powerful and you don't have the proper equipment. Therefore it would be best to quietly sneak past them, therefore avoiding detection (screen above).
After dealing with all the difficulties, you can return to daylight. There, between the towers of Markarth, you will be greeted by Thonar himself - the same who had thrown you into the jail. Curiously, this time he won't try to kill you or throw you back to prison, but congratulate on killing Madanach and tell you that he grants you a pardon. You will regain all of your equipment and additionally receive the Silver-Blood Family Ring, strongly amplifying your Blacksmithing. At this point the mission ends - you're free.