What did you have for lunch today?

Literal

Today what [object-を] lunch [as-に] ate [polite-question-ましたか]?

The に in 昼食に here marks the role/capacity ('as lunch') — one of に's many uses. The full structure 何を昼食に食べる literally 'eat what as lunch' = 'have what for lunch.' This に-as-role usage is common with verbs like する ('do/make'), 選ぶ ('choose'), 使う ('use').