I'm aware that the Macedonian Phalanx was eclipsed by the Roman legion/maniple, but from what I've read that was mostly due to the Hellenistic states failing to properly use it: I.e. they didn't use it properly in conjunction with heavy cavalry, they fought on terrain ill-suited to the phalanx, made the sarissa too long, and didn't support it with other light infantry. At what point in history would the phalanx have assuredly lost even with proper use?
The most direct and least useful answer would be that the Macedonian pike phalanx was objectively obsolete - at least in its European context - by the late 17th century. This was the time when the Swiss-style pike block, the last type of Western heavy infantry exclusively intended for close combat, was phased out, and infantry armies began to consist entirely of men with muskets. Developments in the tactics and effectiveness of firearms (including small arms and artillery) had made the massing of men in tight formations for aggressive close combat too costly and inefficient to be worthwhile, while the invention and development of the bayonet had finally given men with missile weapons the ability to defend themselves against cavalry. In this environment, there was practically no situation in which a tightly packed formation of pikemen could possibly hope to win a battle against a contemporary army.
The more useful answer is that you may need to reconsider how you're looking at this subject. As I pointed out recently here, there's a tendency to regard all forms of warfare as a simple linear progression from primitive weapon systems and tactics to more advanced ones. If I'm not mistaken, this is also the foundation of your question. Your question implies that you think of the Roman legionary as an objectively better warrior than the Macedonian pikeman. However, this evolutionary vision simply doesn't apply to all ages and all forms of fighting. While modern technological advances quickly render earlier weapon systems objectively obsolete, ancient weapon systems were not necessarily superior or inferior to one another in all cases. Mostly, victory was a matter of when, how, and by whom certain weapons and tactics were used.
The pike phalanx, for instance, was a highly effective but extremely specialised weapon. By the time the Romans encountered it, it was a carefully crafted machine intended to defeat other pike phalanxes in regular pitched battle on level ground. In this context, it was extremely effective; indeed, until the advent of effective field artillery, it is difficult to imagine a more effective weapon system. However, outside of this narrow context, it was highly vulnerable. It was unwieldy, slow, easily disrupted, and vulnerable to missiles and flexible troops. As such, it could only function in battle if support troops could help isolate it against enemy attempts to disrupt or surround it.
Generally, even in the time of their wars against Rome, the Hellenistic kings proved very capable of securing the tactical conditions in which the pike phalanx could function. Despite what you may have heard, their armies continued to contain large numbers of cavalry, light infantry, and more flexible forms of heavy infantry, which could protect the phalanx against troops hoping to exploit their cumbersome nature. However, with shrewd and flexible unit tactics mostly devised on the spot, Roman legionaries managed to defeat them in a couple of key battles that secured the overthrow of the Macedonian, Seleukid and Pontic kingdoms. None of this proved that the phalanx was necessarily "obsolete", and indeed, the Hellenistic kings did not stop using them until their ultimate absorption by Rome. Rather, they proved that no weapon system, no matter how effective, could expect to win every battle. At worst, it could be argued that the pike phalanx suffered from overspecialisation - but only because it had a very specific intended role, and needed to be very good in that role.
As a result, even on the last day of its existence, the Macedonian pike phalanx remained a viable weapon system for heavy infantry. These phalanxes were well-trained, well-equipped forces that could wreak havoc in the right circumstances, and the support of cavalry and a range of infantry types (from heavy hoplites to light-armed skirmishers) ensured that their vulnerabilities could not be too easily exploited. They were part of a larger tactical system of combined arms; they were never the entirety of any army. They had their part to play and they were well able to play it. Indeed, in later times, the Romans themselves decided to adopt something more like a tight phalanx formation in their wars against the Parthians, realising that in certain circumstances a dense formation of spear-armed heavy infantry had the advantage over their own typical fighting style.
The pike phalanx, then, was not "eclipsed" or "outclassed" by the legionary, but simply defeated by him. This is a historical event rather than a technological inevitability. The phalanx could win, but didn't. Later on, when situations arose where it could also win, it was reinvented. The same applies to the Greek hoplite, or the Roman legionary himself. Only a shift away from the basic premises of pitched battle between heavy infantry armies could truly render any heavy infantry fighting style obsolete.