Basic chemistry of the Shinoda test for flavonoids?
I found one source indicating that the reaction involves the conversion of the flavonoid to the corresponding anthocyanidin. The structure of that resulting anthocyanidin contains an extended system of conjugated $\pi$-electrons, which constitute a chromophore. As it happens, the electrons of molecules containing conjugated $\pi$ systems have energy level transitions corresponding to absorbance in the visible (and also ultraviolet) region of the electromagnetic spectrum. This accounts for their perceived color.

As for the precise mechanism involved, I was not able to find any sources whatsoever. It's obvious that the flavonoid is reduced, with the magnesium metal being the reducing agent. It could be the process occurs by single electron transfer (SET) with radical and anionic intermediates, or via a cyclic transition state and carbenoid intermediates with coordination of the magnesium, or something else entirely. In any case, the purpose of the acid is likely to activate the carbonyl of the flavonoid to reduction by protonating it, and providing a source of $\ce{H+}$ ions for the subsequent formation of water.

(I find it unlikely that a definitive mechanism for this reduction has been determined, if only because the mechanisms of many similar reductions involving metals and mineral acids widely used in synthetic organic chemistry have yet to be entirely resolved.)