He can’t be compelled to testify against himself in general. The extent to which that can be held against him in court varies from not at all in criminal cases to somewhat in civil cases.
The point of announcing this last minute was legal strategy - the prosecution’s team would have spent a long time preparing to cross-examine Trump. All that time is now wasted. That was the point. He probably never intended to actually testify.