It's needed in such sentences which show amazement, or surprise, also questions.
Co to był za mecz! = What a game that was!
Co to za butelka? = What (kind of) bottle is that? (Why is it here?)
A co to za wygłupy?! = What is this fooling around?!
(just some quick examples as I'm kinda in a hurry)