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.
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.