There are many ways to answer this.
One, if a person buys a package of sessions from a personal trainer, and has scheduled an appointment and paid in advance, then that person has much greater motivation to actually get to the gym.
Two, maybe someone wants company while they work out. At the gym I go to, I listen to the personal trainers interact with their clients, and most of it consists of banter about the weather, sports, children, pets, movies, and such. It is pretty obvious these These personal trainers provide a little distraction and pleasant company. Nothing wrong with that.
A third reason might be, that they hope a personal trainer will help them with technique and form. Having somebody watch you and give feedback about what your body is really doing can be extremely beneficial. Sometimes a trainer needs to physically manipulate a client's body to correct their movement pattern. However, from what I see at the gym, most personal trainers don't do enough of this. I've see lots of terrible form on display while personal trainers are chatting about the weather. So, some trainers are more diligent than others about giving clients useful feedback.
Fourth, even with the internet, there is work involved in putting together a itinerary of exercises. When I lead an exercise class, I compile exercises from a multitude of sources. A list of my sources would require a small book and I'm adding new sources every week. Some of my exercises come from scholarly research and aren't found on youtube. The average person is not going to invest this kind of time into compiling a workout itinerary. On the other hand, many personal trainers these days just copy their workouts from youtube videos. Again, what you get from a personal trainer depends on exactly who you hire and how much you are willing to pay.