How it works
を (object) marks ケーキ (cake) as the thing being offered, but the verb that would normally follow — take it, eat it — is left unsaid. どうぞ (please) carries the whole offer on its own: it's the warm "go ahead, help yourself" you say when handing something over.