Trump endorsed Ryan because Ryan is ahead by 66 points. If Ryan won by such a margin without Trump’s endorsement, it would make it look like Trump’s endorsement doesn’t matter. It would make Trump look non-influential and unimportant. That’s why he endorsed him.
That sums it up well