You need to do 9 full sets with max Tempo, so you'll need at least 36 non-Shadow Pokemon to do this with, setting them up to face each other's strength.
I'll give you an easy example:
Houndour > Hoppip > Spheal > Sandshrew because:
Fire > Grass > Water > Ground > Fire
Remember the last one in the set needs to be weak to the third but strong to the first, like the Sandshrew in the above example. Do this in every set, all nine of them, then place Lugia in one of the sets (you can place other Pokemon that are ready to be purified in any of the others if you wish). It will say Lugia is acting funny, and it's Heart Gauge will glow white. This shows it can now be purified, so do so.