After the conquest of Wales by Edward I, the military need for castles lessened. When gunpowder and cannon were invented, castle defences could be damaged or destroyed more easily. Battles between armies were fought away from castles on open ground.
During the campaigns of Owain Glyn Dwr against the king, castles came back into use for a while. In 1404 Owain Glyn Dwr captured Harlech Castle and it became his headquarters for five years and a setting for his parliament.
When Wales and England became one country after the Acts of Union (1536-43), the country became more peaceful and castles were not needed for defence. Some were used as centres of administration, where rents and taxes could be collected. Courts of law were held at some castles, and their dungeons were still used as prisons. If castles were used in this way, the rooms were adapted to provide offices and accommodation for the officials who carried out these duties. Other castles fell into ruins. Kidwelly Castle was used as a court until 1609.