Was Black Zetsu made by Kaguya this whole time? Or did Madara (being her reincarnation) accidentally create her will, which once fused with Madara became Kaguya again?
Black Zetsu was created by Kaguya Ōtsutsuki shortly before she was sealed as the Ten-Tails by her sons. Black Zetsu was created from the will of Kaguya Ōtsutsuki. With the goal of reviving Kaguya Ōtsutsuki, Black Zetsu manipulated Indra and his descendants, the Uchiha clan, along with Asura's descendants, the Senju clan, in an attempt to get one of them to awaken the Rinnegan. Madara Uchiha eventually succeeded in doing so, and Black Zetsu began secretly manipulating events to have Kaguya resurrected. He succeded when he had the rennigan and enough chakra to do so.
Black Zetsu was created by Kaguya Ōtsutsuki before she was sealed as the Ten-Tails by her sons, Hagoromo and Hamura.
When Madara was on the verge of death, he believed he had created Black Zetsu by imbuing his will into half of White Zetsu, and that the complete Zetsu was partially his clone.
It wasn't created by Madara. Zetsu only had it look like it. Zetsu is a living chakra manifestation of Kaguya's last resort, and he is basically a product of the black mass chakra that contains all elements + Ying and Yang chakra, which is basically the reason why he is capable of thinking. She created it as a self manifestation in a form of chakra, and he manipulated Madara into believing it was his creation so that he could set the events in motion that would later culminate in Kaguya's reincarnation.
Black Zetsu was created by Madara but it is the manifestation of Kaguya's will. Its aim was always to revive Kaguya and hence it manipulated the Uchiha clan by making changes to the hidden stone tablet. Think of it as Kaguya's will to return while she was being sealed in by her sons which took up a humanoid form as over two generations.