I’m unsure of what exactly you’re asking for. If you want to purely rotate an object by 90 degrees on the Z axis (globally), then you can just use the object’s applyRotation() function. Use math.radians() to convert 90 degrees into radians, or use math.pi to do it yourself (since pi is 180 degrees, half of pi is 90 degrees).
from bge import logic
import math
cont = logic.getCurrentController()
owner = cont.owner
owner.applyRotation([0, 0, math.pi / 2])
With the above explanations you now know that rotation around the Z-Axis changes the X and Y components of the Matrix (which is not complete btw. but sufficient for rotation).
As you want to rotate in 90° steps the calculation of sin and cos is pretty simple (school math).
sin(90°) = 1
cos(90°) = 0
it means this are special cases making life a bit easier ;).
now fill it in the above rotation matrix around Z:
0 -1 0
1 0 0
0 0 1
to rotate -90°:
0 1 0
-1 0 0
0 0 1
Now you multiply this “90° around Z” rotation matrix with the existing orientation matrix to get the rotated orientation.