In the Battle of Noryang, the combined navy of Chosun (Korean kingdom) and Ming (China) tried to prevent the Japanese from making a safe retreat. But considering the fact that the Koreans or the Chinese did not have any intention to follow them to Japan, what was the reason for preventing the retreat? The allied forces must have known that Hideyoshi had died, and the Japanese had no hopes of invading Korea again. Then, why did they not simply leave the Japanese alone, considering the fact that they did not have much to gain even after winning the battle?
The short answer is because they were still at war.
Further, it is not clear to me why you would say "... the Japanese had no hopes of invading Korea again". This final battle is from Hideyoshi's 2nd invasion of Korea in late 16th century.
The longer answer is, and putting this question in context, it wasn't a retreat or surrender but a fighting withdrawal. More importantly, it was in the midst of attempted negotiation (i.e. settlement by the Japanese, not the Korean). The Koreans did not agree to the settlement.
After Hideyoshi's death, the 'Five Commissioners' (Go-Bugyō) tried to hide his passing, by sending correspondence to Choson court:
Our Lord has in the past few days at length been recovering from illness, (but also assert that), some time ago he issued instructions for peace.
The terms offered to withdraw was (emphasis mine):
(Letter from Mashita Nagamori (1545-1615), one of the 'Five Commissioners'): "In exchange for the surrender of the Japanese forts there, they (the Japanese) were willing to accept that a Korean prince be sent as a hostage to Japan or to content themselves with the delivery of an unspecified amount of rice, tiger skins, leopard skins, and honey from the Koreans."
Source - both quotes: The Cambridge History of Japan, Volume 4, 1988, pp. 28-9.
To be clear, it wasn't "they" ("... they not simply leave the Japanese alone"). It was he - Admiral Yi Sun-sin, because the Ming representative, Admiral Chen Lin, wanted to:
The Chinese had clearly had enough of war, and as Chen Lin was willing to let the Japanese go without further bloodshed, he proposed to Yi that he, Chen Lin, should conduct an operation against So– Yoshitomo’s small wajo– on Namhae Island. Apart from the inherent promise of a final portion of military glory, Chen Lin also hoped that Konishi might take advantage of his absence and settle the matter by default by running the blockade. Yi, however, was greatly indignant at the suggestion of an attack on Namhae, which had long been within his sphere of influence.
Source: The Samurai Invasion of Korea 1592–98 (Osprey, 2008), p. 85.
To expand on Amandeep Jiddewar's answer: The Wikipedia article on Noryang referenced by OP seems to indicate that the Japanese were not intending a retreat from the Korean Peninsula, but rather a consolidation inside their fortified perimeter around Pusan. As one of the most vulnerable maneuvers that an army can attempt is a withdrawal in the face of the enemy, and he intention of the Japanese to fully withdraw from the Korean Peninsula were far from clear, the decision to pursue the Japanese and engage them, with the intent of destroying their offensive and defensive capability, seems imminently sensible..
Simply, the Koreans wanted to bloody the Japanese so the Japanese wouldn't be tempted to re-invade again.
The Chinese treated the Koreans as the junior partner in the war, and felt free to ignore Korean concerns during negotiations. The Chinese wanted a stable situation on the Korean peninsula, so they could withdraw from an expensive endeavor, and free their forces for possible use elsewhere.
The Koreans suffered horribly and wanted a measure of revenge. They lost 34% of their arable land, suffered 185,000 casualties, and some 60,000 captives transported to Japan. Population was significantly reduced, although the loss of census records makes the extent of loss hard to calculate. The Imperial city of Pyongyang burned, the Royal palaces sacked, and important archives destroyed. Atrocities were widespread. The Koreans wanted into inflict as much hell on the Japanese as possible.
When the Japanese attempted to bribe the Chinese naval commander to let them go, the Koreans naturally had other ideas. The Battle of Noryang was fought to destroy as much of the Japanese military capability a possible. As a result the Japanese lost 300 of their 500 ships, and some 13,000 battle hardened troops. The Korean-Chinese fleet lost none of their 150 ships, only some 500 sailors, along with naval mastermind Admiral Yi Sun-sin.
Japanese prepared army of 500 ships for peaceful retrieval from Korea to there homeland.
"Japanese had no hopes of Invading again!"
This idea was not convincing for
Admiral Yi, he with his Chinese counterparts resolved to defeat Japanese once and for all and Japanese would never dream of attacking Korea again.