While I cannot speak to the specifics of Ireland and Spain, I suspect their position is quite similar to Norway. Norway recognizes Palestine's right to exist based on the borders from before the 4th of June 1967. Even though Hamas controls the Gaza strip today, Norway is not recognizing Hamas as the goverment of Palestine, or is in any way rewarding them for the terror attacks they committed on the 7th of October last year. Currently it is Mahmoud Abbas, the party leader of al Fatah, who is recognized as the president of the palestinian people. Most countries refer to the Palestinian Authority when talking about Palestine and its future.
For a long time, the promise of recognition as reward for a lasting peace has been the strategy used by Norway, but now a Palestinian state is seen as a prerequisite for peace in the Middle East. Prime minister Støre says, among other things, the following about the recognition of Palestine as a state:
>When we recognize Palestine, we can more strongly encourage other countries to support the building of a Palestinian state and we can hold the Palestinian state accountable
>Recognizing a state is not about giving the green light to every policy a state pursues. We will not support a state that uses violence. The Palestinians must see that there is another hope than the path of violence.
Source in Norwegian: https://www.nrk.no/urix/noreg-anerkjenner-palestina-1.168916...