Some of the problem is the water in the line from the faucet up the pipe to the shower head has cooled and it has to dump so the conditioned water can come out.
Its just like when your AC cycles and the registers blow out hot air. The air that was left in the ducts from the last cooling cycle has heated up from the attic temp. When the fan starts up for the next cycle, this hot air has to be expelled, same for the water.
You never receive hot water immediately when you turn on the hot water because of the many feet of water line in your home that has to be emptied of the existing water in the lines to finally become hot water.