You probably want to be animating the transform’s eulerAngles, not modifying the xyzw of the rotation property itself (transform.rotation is a Quaternion and modifying their properties by hand is where madness lies)
Unfortunately, you can’t easily drive Quaternions by curves either (they’re… complicated; the xyzw components don’t actually describe axis rotations, they indirectly describe an angle around an axis via a bunch of trig functions; you can’t really edit the components specifically and expect it to work).
If you precalculated the Quaternions, you might be able to do it… something like this?
Quaternion rot; //Quaternion we'll be storing the rotation in
float angle = 180; //rotation each keyframe
int time = 20; //time between keyframes
Vector3 axis = Vector3.forward; //define the axis of rotation
int keyframes = 6; //how many keys to add
//the four curves; one for each quaternion property
AnimationCurve xCurve = new AnimationCurve(), yCurve = new AnimationCurve(), zCurve = new AnimationCurve(), wCurve = new AnimationCurve();
for(int k = 0; k < keyframes; k++){
rot = Quaternion.AngleAxis(angle*k, axis); //create our quaternion key for this keyframe
//create the keys
xCurve.AddKey(time*k, rot.x);
yCurve.AddKey(time*k, rot.y);
zCurve.AddKey(time*k, rot.z);
wCurve.AddKey(time*k, rot.w);
}
//set the curves on the clip
clip.SetCurve(go.name, typeof (Transform), "localRotation.x", xCurve);
clip.SetCurve(go.name, typeof (Transform), "localRotation.y", yCurve);
clip.SetCurve(go.name, typeof (Transform), "localRotation.z", zCurve);
clip.SetCurve(go.name, typeof (Transform), "localRotation.w", wCurve);