Legendary Pokemon can be obtained via 5 tier raids. The raid Pokemon change on average once a month.
There is also Special Research that users may complete, with the final reward being a legendary or Mythical. For example, "A Ripple in Time" will give you a Celebi. Some of these are events, and some have to be paid for. However, there is a few containing Mew, Meltan and Celebi that are free to all trainers.
In the past, the breakthrough reward was a Legendary. The breakthrough Pokemon changes every month, and currently, (unfortunately), they do not contain legendary Pokemon. Since the Pokemon is always changing, legendary Pokemon may eventually return to the breakthrough box.
Source: Experience