It didn't last long cause he died in 1922, but for me the real kicker was that at the time he won both elections, he was sitting in jail
The key here is that these were two elections to two parliaments: the Northern Ireland parliament and the Southern Ireland parliament. Under the 1920 Government of Ireland Act, Ireland was partitioned into two home rule governments. By the time the elections were held, however, home rule had been superseded in the South and the elections were treated by Sinn Féin as a renewed mandate/propaganda for Dáil Éireann, the rebel parliament they had established after the 1918 election. The three SF candidates in Cavan (including Griffith) were elected unopposed. The official southern parliament met as a rump made up of Unionists elected for university seats but the SF TDs met as the 2nd Dáil.
In Northern Ireland, the situation was more complicated. The Irish Parliamentary Party was still a formidable force in the region and there was a risk that they and SF could split the nationalist vote to the benefit of the Ulster Unionists. The two agreed to a pact under which they would each contest six seats and both would abstain from the Northern Ireland parliament. SF's candidates were largely also TDs for southern constituencies and they were deemed to represent their northern constituencies (but didn’t get double votes).
Probably the best outline is Eamon Phoenix’s 'Northern Nationalism: Nationalist Politics, Partition and the Catholic Minority in Northern Ireland 1890-1940' For Sinn Féin, Michael Laffan's 'The Resurrection of Ireland: The Sinn Féin Party, 1916-1923' is definitive.