Good question. The lowest energy state of a polymer is a random coil, that is the one that maximizes entropy. When you stretch a polymer and let it relax, it returns to the coiled state as entropy increases (this is also why rubber is elastic). However, if there's no knot it is unlikely (but not impossible) for knots to spontaneously form as it relaxes.
A polymer with a knot is thought to have a higher free energy than one without a knot (there's more configurations without a knot than with a knot, so unknot has higher entropy). What has been theorized is that knots are metastable, meaning there is an equilibrium size for the knot once it exists, and it is unlikely to expand to much bigger than that, so the molecule will remain knotted for a long time, until it diffuses to the end of the molecule and unties. There might also be scenarios in which knots are favourable, like a molecule under extreme confinement (the DNA of a virus is an example).