It’s an ugly and embarrassing story, and I hope that my candor is appreciated in what to me is a delicate matter.
In 1845, a year after the death of Joseph Smith, a black LDS priesthood holder named William McCary, married Lucy Stanton, a white daughter of Daniel Stanton, a former high councilor and stake president. As best I can tell, there wasn’t a major controversy there, which in itself seems remarkable. McCary joined the LDS community in Winter Quarters, Nebraska in 1846-47, when Brigham Young was there. While in Winter Quarters, McCary began claiming powers of prophesy and transfiguration, essentially made a play for leadership. He also started taking multiple white wives, through his own claimed authority, some of whom were already married. McCary was excommunicated
That’s the context in which Brigham Young appears to have enacted the restrictions against Blacks being ordained to the priesthood. McCary settled a short distance away and began attracting some Winter Quarters followers to his own brand of “Mormonism” (big surprise there

)
AFAIK the earliest known statement by any Mormon leader, regarding blacks being restricted from priesthood ordination, was made by Apostle Parley P. Pratt
a month after McCary was expelled from Winter Quarters.
The timing to me suggests a connection.
I can see how the incident might influence Brigham Young into believing that the prohibition was somehow necessary to protect the church. Although from my perspective it does seem politically motivated.