Yes, you sure can buy a Udemy course for someone else. For the matter of fact, many people buy Udemy courses as a Gift for their loved ones. Just watch this video to know the process of gifting a Udemy course.
https://www.youtube.com/embed/pWfeF9Gl60c