The actual trunk does not straighten. Inside the core is exactly the same shape but because the outside is growing thicker in some spots and not in others the inside of curves fills in faster which, over time, makes the outside of the tree straighter.
Maybe this rough drawing will help?
View attachment 449270
Now add more layers each year with thicker growth inside any bends and thinner on the outside of bends. Eventually the trunk grows to become a cylinder just by filling in the hollow parts more than the outside of bends.