Why does this code execute?
If you add a debugging print you will see what is happening:

void setup() {
  Serial.begin (115200);
  Serial.println ();

  pinMode(13, OUTPUT);

  int len = 5000;
  byte *data = (byte *)malloc(len * sizeof(*data));

  Serial.print ("data = ");
  Serial.println ((int) data);
}


Output:

data = 0


The malloc failed, it returned NULL, the rest of the program proceeded normally.




  once malloc has allocated 5000 bytes (or as many as it could of the 5000 bytes)


malloc does not return with a partial allocation. It either allocates the amount you requested or none at all.