While the Germans never worked out that the Enigma system had been cracked, as described in the answer /u/silverappleyard has linked, their allies did. An escaped prisoner of war was able to inform the Italian Navy that the British were reading Enigma messages, leading to the service abandoning the cypher.
The story starts in the aftermath of the Battle of Cape Matapan, where the Royal Navy ambushed and sank three Italian cruisers and two destroyers. Several hundred Italian sailors were captured and taken back to Egypt. These prisoners were questioned at a facility in the Cairo suburb of Heliopolis. One of these prisoners was a sub-lieutenant called Percivalle Levaro, from the cruiser Pola. Levaro had been injured during the battle, suffering from a broken arm. This, combined with the fact that he was being interrogated in French, a language he didn't really speak, meant that he was not very forthcoming in the interview. As a result, his interrogator was indiscreet when another officer, seemingly a personal friend, entered the room. The newcomer had just arrived in Egypt, to teach the procedures needed to decrypt Enigma messages; his conversation with the interrogator disclosed this fact, the techniques the British used and the speed with which the British could break Enigma. There may also have been some coded references to the existence of the Government Code and Cypher School at Bletchley Park.
While Levaro spoke little French, he was fluent in English - he had had a British governess as a child. He understood and memorised what was being said. When he was sent back to the main POW camp at Geneifa, he reported to a senior officer from Pola, Major (Medical Naval Corps) Pietro Cuscianna. Cuscianna agreed on the importance of what Levaro had overheard, and that the Italian high command must be informed as soon as possible. Due to his broken arm, Levaro could not be the messenger of the news; breaking out of the camp might well require athleticisim and an ability to blend in, difficult to do with an arm in a sling. Instead, one of Pola's gunnery officers, Lieutenant Luigi Tomasuolo, was chosen. Tomasuolo memorised Levaro's information and then, using tobacco to irritate his skin, faked a high fever. He was taken to a military hospital, from which he escaped using a stolen British Army uniform. He sought shelter at the St Joseph’s Roman Catholic Church on the island of Zamalek, Cairo. The friars there, two of whom had been Italian Army chaplains during WWI, helped him to the house of a Spanish man who was sympathetic to the Axis cause. Here, he would later be joined by four other Italian officers, who had escaped from the Geneifa camp through a tunnel. Tomasuolo and one of these officers, Captain Umberto Rizzitano of the Italian Army, chose to escape by sea. They used the Spanish passports of their host and his son, with appropriate modifications. On the 30th October 1941, the pair boarded a Turkish steamer, which took them to Iskenderun. Here, they obtained new documents from the Italian consul, and travelled on these to Istanbul. The Italian naval attache there, realising the importance of the information, purchased tickets for them on the Orient Express, getting them back to Italy.
Tomasuolo arrived in Rome in December 1941, where he was promptly imprisoned by the military police as a security risk; the Army believed he might be a British double agent. It took just under two weeks to check his story and his bona-fides. When the confirmation came through, he was promptly promoted to the rank of lieutenant-commander, and given a meeting with the Chiefs of Staff of the Navy and the Commando Supremo (high command). The latter, General Ugo Cavallero, then informed the commander of the German forces in Italy, Field Marshal Kesselring, that the British were reading Enigma messages. The Germans, however did not believe the Italians. This was partly down to a British effort to confuse them. A mole in the German naval command in Rome had informed the British of the leak, setting in motion a series of cover-ups to shift the blame for German setbacks to British spies. Double agents were used to inform the Germans of the existence of British spies watching German and Italian ports. To enhance this, a number of British agents were deliberately 'blown' (revealed to the Axis authorities).
The British countermeasures ensured that the Germans did not believe Tomasuolo's information. They also confused the Italian Air Force. However, the Italian Navy was not taken in. Tomasuolo's message confirmed some suspicions that had been developing in the service following Matapan. An investigation into the battle had suggested that the British could only have known of the Italian plans through the breaking of German Air Force Enigma messages. As a result, the Italian Navy discarded the Enigma machine on the 30th December 1941. However, it should be noted that the Italian Navy were not major users of the machine. They only had ten of the devices, which were only used by the Navy's intelligence unit. Instead, it preferred other systems, largely Swedish Hagelin machines or book codes.
There's always room for further discussion, but you might be interested in this previous answer by u/kieslowskifan: