Why is my Pokémon not at its max potential CP?
As you probably know, you are able to level up your Pokémon twice per trainer level. However, it appears that a Pokémon reaching level 40.0 is a bug that was performed by pressing the Power Up button with 2-3 fingers, but it has since been removed.
Thus, you're only able to power your Pokémon up to level 39.0 these days without the bug. Due to the fact that you're always able to level your Pokémon up to your trainer level + 1.5, your Pokémon will hit their max level when you're trainer level 38 after being powered up one last time. From here:
There was the well known double/triple tap trick to get Pokemon to level 40 if you were already at level 38 and didn't power your Pokemon to 39 (and having the power up bar go away). [...] the gen 2 patches have eliminated that