Rule 1: in Russian each rule has a great number of exceptions.

"пирожное" is an adjectival noun, that is an adjective interpreted as noun. Such nouns are declined according to rules for adjectives.

See here, variant 2 (adjective), "Neuter" column. Or here, "Normal Adjectives - Hard" paragraph, "Neuter" column.