Hundreds of thousands of people have gathered on the streets of Istanbul to protest against the arrest of the city's mayor - as he was due to be selected as an opposition candidate to President Recep Tayyip Erdogan.