Revelation 21:27

there shall by no means enter it anything that defiles
Defiles is κοινὸν [koinon] : common. This speaks of those things which are unclean. At one time, the Gentiles had been considered unclean (κοίνου [koinou] , Acts Acts 10:13). All who inhabit the eternal state and access the city have been washing in the blood of the Lamb (Rev. Rev. 1:5+) and are now clean. There is no more sin. See commentary on Revelation 21:21. Isaiah saw a “Highway of Holiness” over which nothing unclean would pass and upon which the redeemed would walk, those who had been ransomed (Isa. Isa. 35:8-10). A day was coming when the uncircumcised and the unclean would no longer come to Jerusalem (Isa. Isa. 52:1). “Jerusalem shall be holy, and no aliens shall ever pass through her again” (Joel Joel 3:17). See commentary on Revelation 21:8.

only those who are written in the Lamb’s Book of Life
This does not imply that some outside the city may be refused entry at the gates. The gates remain open at all times because only the redeemed and (now) sinless inhabit the new heaven and new earth. What this phrase is saying is that all who participate in the eternal state are the redeemed who were written in the Lamb’s Book of Life and that none of the lost will ever enter the city because they are eternally incarcerated in the Lake of Fire. These are the overcomers of all history, including those during the Tribulation who refused to worship the Beast. Jesus promised the overcomer in the church at Sardis that his name would not be blotted out of the Book of Life. The Beast worshipers were never written in the book (Rev. Rev. 13:8+; Rev. 17:8+). The unrighteous dead were judged by this book: those who were not written in the Book of Life were cast into the Lake of Fire at the passing away of the old order (Rev. Rev. 20:12-15+). See commentary on Revelation 20:15. See Book of Life.