How did black men such as Benjamin Oliver Davis Sr achieve high ranks in the US military during segregation? Those ranks should put them in position of power over white people, not very segregation-like.
As a matter of policy, black officers were only supposed to be assigned to black units. In theory, therefore, segregation was actually designed to ensure that blacks would not be giving orders to whites, regardless of ranks.
Negroes would be utilized in units with all-Negro enlisted personnel, but these units did not need to be employed separately . . . Negro officers were to serve only with Negro units and in overhead installations, and should command Negro troops only.
Lee, Ulysses. The Employment of Negro Troops. Government Printing Office, 1966.
Your example of Benjamin O. Davis Jr illustrates this policy. Upon graduation from West Point, the future general was assigned to the 24th regiment, an all black unit. He was promoted to captain in October 1940, in preparation for the creation of an all black flying unit, the Tuskegee Airmen, and became a lieutenant colonel in 1942 when appointed commander of the same.
It's worth noting that none of General Davis' above promotions, not even captain, was made permanent in the regular military until after the Second World War was over. In terms of high rank, he did not become a brigadier general until 1954, long after Truman ordered the desegregation of the military.
His father, Benjamin Davis Sr, however, was promoted to general in 1940 at the same time FDR formalised the acceptance of segregation by ordering the formation of all black units. In this case Roosevelt apparently wanted to forestall African-American criticism, by promoting the only black colonel in the military to general rank.
I don't know if you have a specific period in mind, but the military desegregated earlier than most of the rest of the country. When Truman signed Executive Order 9981 (1948), it allowed for desegregated units. Before then, units were divided by race.