An explicit "will" is suppressed in "if" clauses. For instance, "I buy a car tomorrow" doesn't sound right unless there is some sort of schedule involved, and since it's a future action, you'd say "I will buy a car tomorrow." Yet in an "if" clause, the "will" disappears: "If I buy a car tomorrow, then ..."
Now (getting to the point), in your case, the sentence "They would have been painted ..." is grammatically the past tense of "They will have been painted ..." But the sentence is in an "if" clause, so the "will" is suppressed, as is normal, and we get the past tense form of "They have been painted ...", which is "They had been painted ...".
I know, the "would" isn't really a logical past tense, but grammatically, it sometimes behaves as though it were.
So the answer to your question is this: The grammatical problem is that "will" wasn't deleted from the "if" clause.