KABUL, Afghanistan (AP) _ Foreigners captured after entering Afghanistan with Moslem guerrillas have been caught up in the Kabul government's effort to win international credibility.

As the Soviet Union's troops withdraw after nine years of helping the Afghan government fight the guerrillas, the quest for peace is incref the political campaign. Two Turks who joined the Afghan guerrillas and a West German doctor and nurse who were working in a guerrilla-controlled area are the latest pawns in this game - all four are being held in Kabul's Pol-e- Charki Prison.

Most Western nations have refused to recognize or deal with the Afghan government since Moscow's 1979 intervention that sent more than 100,000 Red Army troops into Afghanistan to bolster the Soviet-style regime.

Afghan officials have made it clear the Turks' prison terms could be shortened if President Turgut Ozal of Turkey appeals to President Najib for clemency, according to a diplomatic source who spoke on condition of anonymity. The Turkish government has refused to do so on the grounds that humanitarian issues should not be mixed with politics.

Appeals addressed to Najib by President Francois Mitterrand of France and President Francesco Cossiga of Italy resulted in the freedom of a French journalist and an Italian photojournalist 4 1/2 months ago. The two men had been convicted of espionage and of entering Afghanistan illegally.

France and Italy were criticized by some of their Western allies on the grounds the appeals constituted de facto recognition of the Afghan government.

The Turkish and West German prisoners were accused of entering Afghanistan illegally from Pakistan. They four have been visited in prison by representative s of their governments.

One of the Turks, Turgut Uzel, 22, was captured in 1984 and is serving a 16-year sentence. The other, Osman Demir, 24, was captured in December 1987 and is serving a 20-year term. Both were convicted of illegal entry and espionage.

West German doctor Benno Splieth and nurse Lea Hackstedt were captured Sept. 8 and accused of illegal entry. Afghan news reports also said they were spying. They have not been tried.

A Western diplomatic source, speaking on condition of anonymity, said there has been no suggestion that an appeal for clemency would hasten the Germans' release. But he noted that West German diplomats have been allowed to visit Splieth and Ms. Hackstedt twice since their capture - on Sept. 25 and on Sunday.

The speed with which the visits were arranged was several months faster than those accorded foreign prisoners in the past and appear to be part of the Afghan government's move to present a more humanitarian face to the world.

Similarly, the International Committee of the Red Cross this year has been allowed to visit Afghan political prisoners for the first time in the war.

France, Italy, West Germay and Turkey - along with the United States, most other Western nations and some non-Western ones - withdrew their ambassadors in protest of the Soviet intervention in Afghanistan. Their embassies in Kabul are headed by charge d'affaires.

Their contacts with the Afghan government are kept at a minimum. They consist primarily of meetings with Foreign Ministry officials over visa and other consular matters and with security forces over safety measures for embassy grounds and staffers.

The two West German prisoners and one of the Turks are in good health, according to the diplomat sources. The other Turk, Demir, appeared to be emotionally disturbed, one source said. The sources spoke on condition of anonymity.

The Turks were last visited by a representative of their government Oct. 6. The diplomat familiar with their situation described them as ''adventurers'' and said the espionage charges were unfounded.

He said Uzel was accused of spying for the CIA, while Demir was accused of being a West German agent. He said Uzel previously went to Iran to fight Ayatollah Ruhollah Khomeini's Islamic regime. Uzel was captured by the Iranian Revolutionary Guards but escaped and soon joined the Afghan guerrillas.

Uzel was captured in Jawzjan province which borders the Soviet Union, while Demir was captured in Kandahar province which borders Pakistan.

Splieth, who is in his early 30s, and Ms. Hackstedt, who is in her late 20s, were working with a West German private relief organization called Committee Cap Anamur, according to the Western diplomatic source.

They were captured near Ghazni while returning to Pakistan after working at a dispensary in Bamyan province west of Kabul.