No, you don't have to pay for spells you gain when leveling up
From the PHB, p. 114 sidebar:
The spells that you add to your spellbook as you gain levels reflect the arcane research you conduct on your own, as well as
intellectual breakthroughs you have had about the nature of the
multiverse. You might find other spells during your adventures. You
could discover a spell recorded on a scroll in an evil wizard's chest,
for example, or in a dusty tome in an ancient library.
Copying a Spell into the Book
When you find a wizard spell of 1st level or higher, you can add it to your spellbook if it is of a level for which you have spell slots
and if you can spare the time to decipher and copy it.
As you see, the rules establish a clear difference between spells that add to your spellbook and those that you find and copy into it. If you take a look at the next part, you will know why.
Copying a spell into your spellbook involves reproducing the basic
form of the spell, then deciphering the unique system of notation used
by the wizard who wrote it. You must practice the spell until you
understand the sounds or gestures required, then transcribe it into
your spellbook using your own notation.
For each level of the spell, the process takes 2 hours and costs 50
gp. The cost represents material components you expend as you
experiment with the spell to master it, as well as the fine inks you
need to record it. Once you have spent this time and money, you can
prepare the spell just like your other spells.
As you see, the process of copying involves a lot of time, effort and materials which are dependent on you not yet knowing the spell and reproducing it yourself. For spells which you gain as you level, you skip all of this. The final sentence in the section makes it clear that once the spell is copied through this process, you can prepare it just like your other spells. This implies you do not go through this process for your other spells and that this is a different method of adding a spell to your spellbook.
Lastly, on the same page you are given these simple instructions on what happens when you gain new spells and when you do so.
Learning Spells of 1st Level and Higher
Each time you gain a wizard level, you can add two wizard spells of your choice to your spellbook.
And there is nothing more to it (aside from level restrictions on the spells).