About the time that the Axis was going to run out of territory to lose in Libya, "Operation Torch" took place farther west in north Africa, whereby Allied forces invaded French Morocco and Algeria. Both of these countries plus Tunisia were French territories and controlled at the time by Vichy France, which was nominally neutral. The idea was for the Americans (with lesser British assistance) to get the Axis in a pincer from west and east. The Germans could see what was happening in Vichy-controlled north Africa, and when the those French territories went over to the Allied side a couple of days after "Operation Torch", they started pouring reinforcements into Tunisia, which by then they figured was fair game and no longer nominally neutral. The Axis infused large numbers of men into Tunisia to meet the Allied threat from the west. By far and away, most of the Axis forces fighting in the Tunisian campaign were relatively new to the battle and a much smaller number had been rolled up into Tunisia from Libya by the British fighting from the east.
Once the British steamroller got going to push the Axis out of Libya, Rommel had warned Berlin that further operations in north Africa were pointless and any such resources so committed would be better off applied to the Russian front. Rommel had first-hand knowledge and experience of the capabilities of Allied resources, in particular air power. From about mid-1942 onward, his observations about the supremacy of Allied air power and the relative absence of the Luftwaffe is a common thread in his views on the probable outcome of the war. These impressions were greatly reinforced by his later experiences against the Allies in France in 1944.
We can only surmise that when Berlin made the decision to go into Tunisia and hold onto a position in north Africa, they were not making their decisions on any basis in reality as experienced by Rommel.

