There's nothing stopping them selling the house and investing €400,000 into a pension. This would be two unrelated transactions (i.e. the source of the €400,000 pension contribution would be irrelevant.)
It might not be suitable for them, however. Tax relief can only be claimed on pension contributions up to certain limits, which depend on your parents' age, employment status, income and certain other variables. If they're not going to get tax relief on the €400,000 contribution it wouldn't really be advisable.
If the object of the exercise is simply to provide them with an income from the proceeds of the house sale, they might be well advised to put the maximum allowable contribution into a pension fund (which may be lower than the €400,000) and invest the rest into an income-generating investment product (not a pension).
But there are many, many variables to be considered, including your parents' attitude to risk, tax considerations in Spain, their age etc., so they really need to take professional advice before making a major decision like this.