Interaction of a laser pulse with a target. I. Photoelectron mechanism of generation of a spontaneous magnetic field