I'm under the impression that their end was caused by cannons and line-of-battle tactics in the early modern period (Spanish Armarda) but did more conservative shipbuilders continue to use the architecture or was it a rapid shift as nations raced to have fast, stable ships?
The transition was gradual, happening for the majority of the 16th and early 17th century. During that time we have paralel building of carrack-type ships (called in Iberian peninsual nau/nao) with large forecastles and sterncastles which had primarily cargo carrying role; and since around 1520s we have emergence of a new design, the galleon, which had a more combat role, and who had the forecastles slowly reduced until they were finally completely abandoned.
So if we look as early as the Anthony roll from the 1540s, the muster of English naval ships with images, there are separate rolls for carracks, which looked like this, and for galleasses (galleons) which looked like this. We can clearly see that galleasses still have some sort of forecastle, but it is much smaller then the carrack forecastles. Meaning there was parallel development of both.
The same division happened pretty much everywhere, so for example here are two Portuguese images from the 1540s which shows both galleons with smaller but still present forecastle and few naus with larger forecastles.
English, for their reasons, eventually decided to abandon the carrack design and pursue mostly galleons and developed them further into their famous race-built galleons of the Armada which had lost the forecastle and even the sterncastles almost completely. The Portuguese on the other hand, while also building galleons, continued to build their naus as the main cargo ships for bringing goods from Asia well into the 17th century. So for example in the shipbuilding manual of the 1616 we have instructions for smaller galleons without the forecastle but also for larger naus which still held some sort of forecastle.
All in sum, the process of removing the forecastle began in 1520s with the emergence of galleons. The following decades we had parallel build of ships with and without (smaller) forecastles. The English moved away from the forecastle ships by the end of 16th century with the Portuguese and Spanish continuing to build them for their cargo ships, parallel to their no-forecastle designes, for some decades afterwards until the mid 17th century.