The purpose is to achieve PR.
Hitting Tel Aviv won't achieve anything meaningful, but it will hurt the Israeli and that's all Iran/Hamas/Hezbollah wants.
Or rather, to phrase it better, and based on the name given to that retaliatory strike by Iran, "severe punishment", that's the only thing Iran can hit with the certainty it will hit something. Target a densely populated area with a spam of missiles, a lot won't get there, a few will reach the intended area. Iran will take that as a victory and run victory laps with it, and its supporters will cheer and clap.
Meanwhile that won't deter Israel, that won't stop Israel to conduct strikes, etc... Because Iran can't do anything of these things to begin with.
But the strike occurring at night, and the balls of fire coming down the sky at full speed, and explosions, etc make for good optics. And to the masses it is all that matters.