Is iit safe and how far would it be to walk from the cruise terminal to St. Sophia?
Its more likely that you would dock at the official port across the river from the church/museum, so the walk would be long and a taxi might suit you better. In October our ship docked at the foot of the hill where the Blue Mosque and more are located. It would be safe to walk, very steep and winding streets however. I googled your topic and this map lays it out:
Are you in good shape. Bit of a walk but a wonderful way to get a feel of vibrant Istanbul. However, if there is a time constraint and with cruise dockings there usually is, grab a taxi. You'll cross the Galata Bridge and head into the Old Town. For the life of me couldn't figure out what St. Sophia you were talking about then the light bulb went off, Hagia Sophia. Istanbul is a fascinating, safe, city with wonderful people and food. Hagia Sophia is absolutely stunning. Was there in May, walked around at night taking photographs (my livelihood and passion), never once felt any threat or worry.
Worth a cab ride.