This is an interesting question combining the history of crosswalks, pictograms and traffic lights.
It’s known that pedestrian cross-walks existed in Roman empire more than 2000 years ago. These were raised stone paths across the roads that doubled as severs.
History of traffic lights starts in railways. First traffic lights in city centre were actually pedestrian lights installed in London 1868. Unfortunately the gas lamp caused an explosion which killed a policeman and the idea of traffic lights was forgotten for 50 years, until in 1914 in USA modern traffic lights were installed to help problems caused by high number of motor cars.
Third part of the answer is about the history of the “male and female” pictograms. these were invented in a museum in Vienna back in 1924 to help people who could not read the written text in signs. The modern toilet signs were included in the pictograms and since then people have associated these 2 stick figures to men and women.
It’s not well known when they started using a stick figures in pedestrian traffic lights. Basically the figure is just a “person” without a gender, but the association from toilet signs leads us to think he is a man. Actually in East-Berlin they used symbols where the person had a hat to clearly indicate he is male.
As a response to that many cities have since then used permanent or temporary setup of custom traffic light persons, male, female, kids, couples etc.