You're confusing Donald Trump with Barack Obama, it seems.
Trump has been all of the map on the Iraq War and didn't run on the issue since it was old news by 2016. Obama, on the other hand, made his opposition to it the centerpiece of his campaign and ran as the anti-GWB candidate.
Old news by 2016? He went after hillary for her support of the war. He went after much of the establishment gop for supporting the war. He might not really believe it, but he used part of his campaign to be against it, even though he was all over the map as you say.