well considering jaws originally evolved from the first set of gill arches and eels still have gill arches, so it's not that much of a stretch. Most fish gill arches already have muscle attachments that aid in swallowing and breathing. Many bony fish already have pharyngeal teeth to aid in swallowing (they teeth prevent the prey from being pushed back out of the mouth by water pressure. Moray eels have a much more direct mechanism becasue they live in burrows and can't fold the gill arches out to generate suction and pull food down the mouth as other fish do. So instead the muscles pull the arches backwards and the shape pulls them together pulling food down the gullet.
it has actually happened independently in cichlids and something similar happened in Snakes and Mosasaurs
moray eel jaw evolution
on google or google scholar. $\endgroup$