The flip side of the argument is that Erdogan also knew that the US was leaving at a certain time and decided to call Trump’s bluff. As you insist, an invasion like this isn’t spontaneous and US certainly knew that this could be the outcome, yet Trump proceeded anyway, despite likely warnings from people on the ground.
Trump’s initial gambit was a strongly worded letter, written by an 11-year old. Then Erdogan laughed at the letter and put US troops in danger. While you think that Trump responded properly by showing what the US is capable of, the main point is that it should never have come to that.
So the question is whether the bad guys will be emboldened by Erdogan’s gambit, or will Trump have to escalate his response because Erdogan just emasculated him on the world stage?