When we talk about the phalanx we tend to refer to two different things, and it's important to keep them distinct. The first is the Greek hoplite phalanx, which was a wide rectangular formation of spearmen carrying large round double-grip shields on their left arm. The second is the Macedonian pike phalanx, a line of carefully drilled squares of men wielding very long pikes with both hands and hanging small shields from their necks. The hoplite phalanx seems to have emerged around 500 BC; the pike phalanx was a development of the mid-4th century BC.
(The terminology here is a modern custom, since the hoplite phalanx wasn't called "phalanx" until more than a century into its existence, and Greek sources happily refer to Macedonian pikemen as "hoplites", but we'll leave that aside.)
The hoplite phalanx was the typical core of the militia armies of Greek citizen-states. As such, it largely faded into obscurity when Greek citizen-states lost their role as primary political actors on the Greek stage after the rise of Macedon (late 4th century BC). Their militias simply couldn't compete with the large professional armies of Hellenistic kings. While it's likely that Greek states continued to defend themselves with large numbers of hoplites even into the Roman period, and hoplite mercenaries probably continued to make themselves useful for some time, we don't actually see any description of a hoplite phalanx in pitched battle after the 4th century BC. If any Greek state even deployed a hoplite phalanx against the Romans, the sources don't tell us explicitly.
After the Galatian invasion of the early 3rd century BC, Greek infantry largely seems to have abandoned the old aspis shield in favour of the Gallic-inspired thureos (a larger, oval shield with a central shield boss and spine), which we should probably see as the eclipse of the hoplite and hoplite tactics.
The Macedonian pike phalanx is a very different creature. This professional force was the primary symbol of military power for most of the Hellenistic period, and many of Rome's rivals in the Mediterranean would field them specifically to fight the Roman legions. While most Hellenistic states would eventually abandon the pike phalanx for demographic or financial reasons (traditionally a standing force drawn from Greek and Macedonian migrants, the pike phalanx drew on scarce resources to exist), the last serious challenger to Roman power in the Aegean, Mithradates VI of Pontos, still raised a pike phalanx to form the backbone of his army.
But the fact that it took such an effort to raise, train and maintain a pike phalanx meant that the ultimate victory of Rome caused this type of heavy infantry to evaporate quickly. States that fell under Roman control naturally no longer had their own armed forces. Vassal kings could rarely afford to create their own. There was no reason for anyone to try once Roman supremacy became undeniable. Who would field a pike phalanx after the fall of Macedon, Sparta, the Seleukid and Ptolemaic kingdoms, and Pontos? Why would they bother?
In short, by the time the Romans took complete control of the Greek world in the early 1st century BC, the hoplite phalanx had long since fallen into obscurity and the pike phalanx simply wasn't viable anymore. The peace imposed by the Romans did the rest. Neither hoplites nor pikemen ever made a comeback on ancient battlefields.
Not to discourage any further answers but you might be interested in this answer /u/Iphikrates and /u/Marce_Camitlans. They joined forces once again to forge those answers into this sharp article on Ancient World Magazine.