Much of this is speculation, but will try to backup opinions with links.
Turkey - Iran
Common ground vs Kurds. Despite the religious differences, both countries find common ground in fighting Kurdish independence. https://www.reuters.com/article/us-mideast-crisis-kurds-referendum-minis/turkey-iran-iraq-consider-counter-measures-over-kurdish-referendum-idUSKCN1BW1EA
Oil. There's a larger deal apparently being inked that involves Russia and a 7 billion USD deal, but more long standing https://en.wikipedia.org/wiki/Tabriz%E2%80%93Ankara_pipeline "The Turkish section, operated by BOTAŞ, cost US$600 million. The Turkish annual import consists normally 11 billion cubic meters of natural gas." Can usually trace good relations to money.
$10 billion in trade between the 2 nations, both countries benefit greatly from cross border tourism as well.
Turkey neutrality on Israel - Iran policy. Turkey recognizes Israel, but has otherwise remained very neutral towards the conflict.
Military equality / standoff. When it comes down to it, there really is no clear winner in a conflict between these two nations. http://armedforces.eu/compare/country_Iran_vs_Turkey sometimes a balance of power maintains peace.
Turkey - Saudi relations. Despite the two nations having common sunni populations, they have had a rough history and the Saudi's have little influence within Turkey and very often, Turkey opposes Saudi efforts. http://www.independent.co.uk/news/world/middle-east/qatar-crisis-turkey-saudi-arabia-uae-egypt-economic-sanctions-blockade-air-base-a7805346.html This is much different than Pakistan that readily accepts help and policy from the Saudi's that Iran heavily resists.
Pakistan - Iran
This was a closer relationship further back...Iran was the first state to support (50's) and recognize Pakistan as a separate entity from India. However that has changed in more recent years as Pakistan went from friends to rivals during the Iranian revolution in 1979. For a brief time, Iran and Pakistan supported the Mujahideen in Afghanistan...with Russia support for Iraq and Pakistan support for Iran in the Iran-Iraq war, Pakistan and Iran saw several reasons to grow closer. But that changed...the Mujahideen were two very distinct groups and Pakistan supported the Sunni Taliban explicitly which the Shia Iranians did not. After Russia was gone, the Iranian backed Tajiks and the Pakistan backed Taliban started another conflict for control of the region. Pakistan was thrown into this odd position of keeping allies on the US and Saudi side happy at the same time as the Iranians. This culminated in 1998 http://edition.cnn.com/WORLD/meast/9809/15/iran.afghan.tensions.02/index.html when the Taliban killed several Iranian diplomats and citizens and reporters (just after the Taliban had slaughtered Shia in Mazar-i-Sharif). This led to Iran building up its military and prepping an invasion of Taliban controlled Afghanistan (odd that it would be the US that eventually topples the Taliban rule). Iran actually became a major criticizer of Pakistan Nuclear efforts around this time. Pakistan has actually blocked several attempts from Iran to get this nuclear weapon technology since, a point that likely sours this relation further.
By the 90's, Iran and Saudi Arabia were involved in a proxy war within Pakistan. At one point in time, it was declared that Ayatollah Khomeini is a symbol of Islamic insurgence and Pakistan Sunni's were preparing for the conflict to spill into their lands.
Couple other points:
Pakistan - US relations. I'm not 100% clear on Pakistan's reasoning, but they've always had a slightly more 'pro-US' view than the majority of Muslim states and this has always had them in tougher relations with Iran (added to clarify, this had them in tougher relations with Iran post Iranian revolution '79, not 'always').
Pakistan support for the US led "war on terror". Iran feared they were next, especially after being labelled as part of the 'axis of evil' by Bush, and Pakistan would be key in a US led invasion of Iran. (The axis of evil declaration and US involvement in Afghanistan was always a bit strange...Iran actually supported the efforts to remove the Taliban, while the US allied with Pakistan who supported the Taliban).
Cross border militants. Sunni 'Taliban' and other elements within Pakistan are launching attacks into Shia Iran, Pakistan failure to contain this has resulted in Iran mulling about military action into Pakistan territory to put an end to it themselves. This is very a very stark contrast to Turkey-Iran efforts vs Kurds in Iraq.
Pakistan - Saudi ties. Saudi's continue to fuel the fire in Sunni vs Shia relations and Iran holds Pakistan responsible for not ending the relation. This is in stark contrast compared to Turkey - Saudi relations.
Oil! Had to come up, Iran - Pakistan - India oil deals have repeatedly fell through and have only gained a little momentum in the past 10 years. Of course, Pakistan's ear is always open to the US
If I had to summarize in a single line as to why the relations are different...I'd go with Turkey opposes Saudi Arabia while Pakistan supports their efforts.