I doubt he wrote and delivered his speech thinking that he would probably sabotage his career. He's too calculated, too self interested and believes in his ideas too much to knowingly throw away his entire career. I think he understood the risk but believed it was worth the reward - being the only major candidate who didn't back Trump in 2016.
At the moment, it appears he miscalculated the risk, and I doubt he'll ever recover (could be wrong).
I think Ted Cruz was in a lose-lose situation. If he endorsed Trump he loses all credibility as a man of principle and becomes associated with Trump's rhetoric, racist policies, etc. And if Trump fails in his bid for the presidency or has a failed presidency, Cruz would go down with the ship along with everyone else who supported Trump. And considering the gridlock in Congress, the next president is doomed to a failed presidency, because both parties will do whatever they can to undermine whoever wins the 2016 election. The Republicans set a precedent for undermining a sitting president of the opposite party, and the Democrats will be only too happy to return the favor.
If Cruz doesn't endorse Trump, he maintains his dignity but alienates a large part of the Republican party. His best bet in 2020 would be to run as an independent candidate. He is too disliked in his own party to ever win its nomination. His speech last night was the beginning of his 2020 campaign.
I'm a Progressive and would never consider voting for Cruz due to our differences on social policy, but I respect Cruz's commitment to his beliefs. He can hold his head high, and his children will be able to look back with pride on their father's principled stance. The same can't be said of Rubio, Christie, Carson, and many of the others.