Is it legal in the United Kingdom for an elected parliamentarian (considering both houses)to switch parties? If not, what action is taken against the person?
Is it legal ... to switch parties
Yes, there is no law prohibiting this. Nor should there be.
It is worth remembering that the electorate are asked to elect a representative, a person. The ballot paper does not offer a choice of party to vote for, nor a choice of leader.
The elected member of parliament is then required to represent the whole constituency, including electors who voted for other candidates.
If not, what action is taken against the person?
It is, but let's continue.
If the elected representative does not do the job the electorate expected her to do then they throw her out at the next election.
If we make the mistake of choosing a fickle representative, we have to live with the consequences of our misjudgement for the next five years.
An obvious follow-on question would be - is there any way at all of sacking and replacing an MP?
The Representation of the People Act 1981 provides for MPs lose their jobs if convicted of a criminal offence and sentenced to more than a year in prison. They can subsequently stand for election.
Switching between political parties is not a criminal offence.
The Recall of MPs Act 2015 provides a process where MPs can lose their job. In that case a by-election is held. The grounds for recall seem to be limited to
- a custodial prison sentence,
- suspension from the House ordered by the Committee on Standards, or
- providing false or misleading expenses claims.
It appears that current and recent parliamentarians prize their right to change their mind on subjects of interest to their constituents. Doing so is no bar to office.
It is not illegal, and is common enough for there to be a term "Crossing the floor"
If one doesn't count those who quit their party and sit as independent MPs, or who are sacked from their party (called "having the whip removed"), or who leave to join a minor party. The last person to cross the floor between the major UK parties was Quentin Davis. He was elected as a Conservative in 1987, but crossed the floor to join the Labour party under Gordon Brown in 2007. He is currently a Labour Peer in the Lords.
Alan Howarth has held Government positions first as a Conservative under Margaret Thatcher, then as Labour party member, under Tony Blair. In the 1970 Reg Prentice went the other way, leaving the Labour party and subsequently joining the Conservatives, following disputes with local labour party activists.
Perhaps the most famous politician to cross the floor was Winston Churchill, who moved from the Conservative to the Liberal party in 1904. He later returned, and became Prime Minister as a member of the Conservative party.
Crossing the floor is not illegal, and there is no requirement for an MP to stand down or face early election if they cross the floor of the house.