On our site, we have different backgrounds colours for various forms, and the designers have assigned different colours for the error messages, depending on the background. I was wondering whether there were any usability issues with this approach, as error messages will not be in a consistent colour. Would it be better to have one colour to represent the error messages and use the same across all forms?
Yes, it would be best to display the error messages to the user in a consistent way throughout all of the forms.
Consistency and standards: Users should not have to wonder whether different words, situations, or actions mean the same thing. Follow platform conventions.
Since the site you're working on has various forms with different background colors, you could suggest displaying the error messages in a neutral colored area. It's good that you're not relying solely on color to communicate an error to the user. Here is an example of how a neutral colored error panel could sit on a variety of backgrounds without clashing (and as you know don't rely on red text solely to communicate "error").
Repetition is an important design element to help the user from having to think too hard about what's going on or getting confused. Recognition is also important, and if they don't recognize what's going on, it can lead to frustration for the user.
There certainly may be accessibility problems related to using different color schemes and pairings. It's best to pick something that is easily visible on all themes, and something that would be easily seen by people who may be color-blind or otherwise visually impaired.
You have to be CONSISTENT. Which is exactly why you need to use CHANGING colors on different backgrounds. Colors are always perceived in relation to other colors. A gray on red looks different from the same gray on green.
The squares of the upper row appear to be gray, but they are tinted as shown in the lower row that exchanges between the left fives and the right fives.