A division bench of the Peshawar High Court headed by Chief Justice Dost Muhammad issued the order in response to a petition filed by a lawyer named Arif Khan.
The judges said authorities should take immediate measures to block blasphemous and disputed material on social media websites.
The Chief Justice observed that anti-Islam material on social media websites incite religious sentiments and "cause chaos in society".
They also issued notices to officials of the Interior Ministry, Pakistan Telecommunication Authority and other departments, seeking detailed replies on the issue within 20 days.
YouTube, the popular video sharing website, has been banned in Pakistan since last year over the hosting of clips of an anti-Islam movie.