Where does the value of entity come from in a field of a content type?
It's literally magic (well, PHP magic methods anyway). 

FieldItemBase implements __get(), which will respond to any property on the object (existing or not):

public function __get($name) {
  // There is either a property object or a plain value - possibly for a
  // not-defined property. If we have a plain value, directly return it.
  if (isset($this-&gt;properties[$name])) {
    return $this-&gt;properties[$name]-&gt;getValue();
  }
  elseif (isset($this-&gt;values[$name])) {
    return $this-&gt;values[$name];
  }
}


And the image field type extends the entity reference field type, which maintains an entity property (see EntityReferenceItem::propertyDefinitions).

So when you request the non-existent entity property on the field class, FieldItemBase hooks it up for you via the $properties array, and you get an entity back.