There are a number of different reasons, we'll start with the practical and then move on to the strategic.
- Fuel economy
An even layer of paint makes the surface of the plane more slippery and reduces air resistance. It does not matter what color the plane is painted in, but planes are repainted at regular intervals to restore this property and save fuel. This reason alone is enough to make it worthwhile to paint the aircraft. The procedure for painting a plane costs in the region of one million kronor, and can take up to a week if the motif is sufficiently complicated. - Protective surface
Airplanes are usually built of aluminum, which does not rust and therefore does not need to be painted for rust protection, but on the other hand, airplanes are exposed to extreme differences in temperature. It can be standing still at an airport in the general heat and a blazing sun on top of it, only to be flying around in -50 degrees Celsius in the air a few dozen minutes later. The differences cause the material to expand and contract, which wears out rivets and other things that hold the machine together. To reduce the warming effect the sun has on the plane, it is popular to paint airplanes white (the classic image of an airplane is that it is white, but today we have quite a few airlines, such as Southwest Airlines and DHL, that use other dominant colors. Trump's own airplane is half painted black).
- Branding
The aircraft is the face of an airline. Branding is a huge thing when you want to get customers to pay a little extra just to fly with your particular company. First and foremost, there is a tradition of painting the company's logo on the tail fin, which is also used to be visible during ground movements, but a great many companies (if I had to guess, I would say most) paint their own logos, color patterns or other decorations on their planes to be visible and stand out. Clear examples are Southwest, which I mentioned above, with the dominant dark blue color, combined with red and yellow that really stands out on their aircraft. British Airways strongly holds on to its stylized bird in the logo with the nickname "Speedbird", which has also become the company's call sign in radio communications. Speaking of call signs, a special part of the company Norwegian has taken the call sign "Rednose", which does not refer to any flying reindeer, but to the fact that Norwegian paints the front part of its planes red while the rest of the body is white.
- Marketing
Finally, we have the opportunity to sell the surface of an aircraft to market anything. Unusually painted aircraft get a lot of attention, like large mobile works of art. The company All Nippon Airways (ANA) is the first one that comes to mind when we talk about advertising painted planes. They have done "full body paintings" for brands like Pokémon and Star Wars on several occasions, but they are in good company among many other companies that do similar things. Purely commercial marketing may not be super common, but sometimes airlines create special motifs to, for example, celebrate an anniversary or promote something that the home country is proud of, such as famous people like on Norwegian's tail fin above, or Icelandair's northern lights (under the picture of ANA below)