After the Constitution was amended in the wake of the Civil War, slavery was ended as an institution but those who were freed from bondage were still limited in their choices. Many who did not end up sharecropping worked in menial positions, such as servants, waiters, barbers and railroad porters. These were pretty much the only occupations available to them. For restaurant workers and railroad porters, there was a catch: many employers would not actually pay these workers, under the condition that guests would offer a small tip instead.
It actually started as an economic thing too, because businesses during the great depression weren’t able to consistently pay living wages.
It was originally a way to be able to hire black people and not pay them
It started much earlier than that and has roots in racism. https://time.com/5404475/history-tipping-american-restaurants-civil-war/