As Themas has said, if you have signed an agreement which stipulates that you would need to continue paying until the landlord finds new tennants, you are bound by this agreement and it is perfectly legal.
This type of requirement is usually placed in a Shorthold Tennancy Agreement and is used should the tennant decide to break the term of their agreement, i.e should you decide to terminate your agreement 3months into a six month agreement, you are responsible by the terms f your contract to ensure that your landlord either has payments up until the end of your agreement or gets suitable tennants to cover the term for which you decide not to reside yourself. Hope this makes sense!