Why is Component.transform unavailable outside of functions?

Example:

using UnityEngine;
using System.Collections;

public class temp : MonoBehaviour
{
    Transform t = transform;
}

Gives you the error

A field initializer cannot reference
the non-static field, method, or
property ‘Component.transform’

Example:

using UnityEngine;
using System.Collections;

public class temp : MonoBehaviour
{
    void Temp()
    {
        Transform t = transform;
    }
    
}

All is peachy there.

Can someone explain why I can access it inside of functions, but not outside of a function?

Because field initialisation happens at the creation of the object and a non-static item is not sure to be existing yet. To avoid a corrupted value to be passed, the compiler does not allow to use it.

your code goes down to :

  Transform myTransform = this.transform;

In the method it works because when you call the method (later than initialisation), everything is ready.

Consider that this:

 public float myFloat = 0.0f;

the litteral is constant and static.

You can use static methods because they always exist in the memory and do not access any data that cannot exist (instance data).

By the way, transform property has been improved in latest Unity version and caching is no more relevant.