There are two broad classes of algorithms for time streching/compression: the first stays in time domain, the second goes into frequency domain.
Time domain algorithms are variations on granulation: play small chunks of sound. Consider a tape, to time strech, you read a bit of it with a play head, then you rewind half the size of the chunk and play this bit again, etc. This is good for stationary sounds, but bad for attacks, so maybe you add an algorithm to ignore attacks and strech a little more the moments without attacks. I wouldn't be surprised if the Apple loops worked this way.
If you want to go into frequency domain, you get the frequential information with, for instance, a FFT operation. Then, you go back into time domain, but you can change the time scale easily. When transposing, you can apply filters to preserve formants, before coming back to time domain.
For more information, I advise "The computer music tutorial" by Curtis Roads. But I don't know which software uses which algorithm, and the book will not tell you either.
Best,