U may have only 30 minutes or maximum one hour to see. If u take metro from Airport, and get out in Aksaray station and take light tram in Aksaray to go to Suktanahmet ( 4 stops ) , it will take maximum 30 minutes +10 minutes plus 5 minutes fast walking between light tram and metro station. So total 45 minutes to arrive Sultanahmet with fastest way. But just make it 1 hour maximum in case so you will spend two hours to leave from airport and to go back.
So left with 4 hours, 1 hour to see, so left 3 hours for customs. So thats enough time for u. Customs departure from Turkey is not busy but it sometimes gets too busy in arrivals.
So if u can get out of arrival customs in 1.5 hours maximum, u can do it.
If u think its too risk for u but u still wanna see a turkish town in Istanbul, take metro from airport and get out in Sirinevler station. Its 3 stations next after airport and it wont take more than 10 minutes to arrice Sirinevler from Airport.