Retiring doesn't always means being decomission. It mean that a ship could had been removed from first line duty and transfer to other duties.
Look at the Daedalus class. The USS. Carolina NCC-160 a Daedalus class itself was still in service during the time that Captain Kirk was in command of the Enterprise.
But also, it doesn't mean that they been on active duty during that whole time period. They could easily had been taking off of acting service and put in moatball. Then some years later, taking out of moatball, refited and put back on active service.