I am visiting Turkey as a tourist for one week on Pakistani Passport.
Can I apply for Schengen Visa from Turkey while visiting Istanbul?
In general, no. You are supposed to apply at the consulate responsible for the place where you reside.
There are exceptions for situations where this would cause undue hardship, especially in connection with the requirement that you apply no more than three months before your trip. For example, if you were planning to be in Istanbul for three months, then you would probably be allowed to apply for the visa in Istanbul, because it would not be possible for you to apply in your place of residence without an expensive and time-consuming trip.
Similarly, if you could show that your plans changed in such a way that it was impossible for you to have applied before you began your trip to Istanbul, you might be successful in applying for an exception to the general rule. I suspect that the bar will be rather high, meaning that you would need both a compelling reason for the change in plans and compelling evidence to support it.
Here are some relevant quotations from the Handbook for the processing of visa applications and the modification of issued visas:
2.8. Can a consulate accept an application from an applicant not residing in the jurisdiction of the consulate?
Legal basis: Visa Code, Article 6
As a general rule, only applications from persons who reside legally in the jurisdiction of the competent consulate (as described in points 2.1-2.5) should be accepted. However, an application may be accepted from a person legally present – but not residing - in the jurisdiction of the consulate where the application is submitted, if he can justify why the application could not be lodged at a consulate in his place of residence. It is for the consulate to appreciate whether the justification presented by the applicant is acceptable.
"Non-residing applicant" means an applicant who resides elsewhere but is legally present within the jurisdiction of the consulate where he submits the application. "Legally present" means that the applicant is entitled to stay temporarily in the jurisdiction on the basis of the legislation of the third country where he is present either for a short stay or when he is allowed to stay for a longer period of time while maintaining his permanent residence in another third country.
Example: A Peruvian artist is scheduled to perform in Portugal on 25.5., and from 20.2. to 15.5 she is performing in Canada and the United States.
Under such circumstances a Portuguese consulate in Canada or the United States should allow the applicant to submit the application,because it would be impossible for her to apply while still in her country of residence given the rule of not applying for a visa earlier than three months before the date of the intended entry into the territory of the Member States.
Example: A Chinese professor has travelled to London to teach at a university summer school. During her stay, her father, who lives in France, falls seriously ill and in order to travel to France the Chinese woman applies for a visa at the French consulate in London.
The French consulate in London should deal with the application because it would be excessive to require the person concerned to return to her country of residence to apply for the visa.
Example: A Moroccan national who spends his holidays in Montreal (Canada) wishes to apply for a visa to travel to Germany at the German consulate in Montreal. He claims that the waiting time for obtaining an appointment for submitting the application at the German consulate in Rabat (Morocco) is too long.
The German consulate in Montreal should not accept to deal with the application, because the justification is unfounded.
Example: An accredited commercial intermediary lodges the applications of a group of Russian tourists at the Spanish Consulate General in Moscow. All of them will travel together to Spain for two weeks. The majority of them reside in the jurisdiction of the Spanish Consulate in Moscow while some others reside in the jurisdiction of the Spanish Consulate in Saint Petersburg.
The Spanish consulate in Moscow should deal with the applications.
Example: A Russian businessman from Novorossiysk (Russia) has travelled to Moscow (Russia) for a trade fair. There he meets a Greek business person who invites him to come to Athens (Greece) straight away in order to establish a contract for a future business relationship. The Russian businessman wishes to apply for a visa at the Greek consulate in Moscow because the approximate travel/road distance between Moscow and Novorossiysk is around 1500 km.
The Greek consulate in Moscow should deal with the application because it would be excessive to require the person concerned to return to his city of residence to apply for the visa.