There are a number of factors involved here but mainly frequency response, transient response, signal to noise ratio (S/N) and total harmonic distortion (THD).
[Frequency response][1]Frequency response is largely dependent on the size, shape and mass of a speaker cone and there is no such thing as a speaker with perfect frequency response. But most significantly, the size of a speaker 'tunes' the frequency response of a speaker around a frequency band. This is why most speakers have more than one cone and a crossover to split the input signal and distribute it to the speaker that will reproduce it best. Usually tweeters for high, and speaker cones of varying sizes for the other (lower) frequencies. Laptop speakers usually have one speaker (cone) per channel which is 'pushed' hard to reproduce frequencies it really shouldn't so you can't expect a lot from them.
[Transient response][2]Transient response depends mainly on the amplifier used, as well as the mass of the speaker. Again, a lot of concessions are made to miniaturize these and fit them into a laptop.
[Signal to noise ratio][3]Signal to noise ratio depends on the design of the whole system, even the cabling used and the PCB design. The motherboard of a laptop is a very (electromagnetically) noisy place but most signals are digital and not really affected by this but a digital signal has to be converted to analogue to be sent to the laptop speaker and from what I've seen in laptops I've opened up for repairs, all have single (unshielded) wires.
[Total harmonic distortion][4]Total harmonic distortion is probably the most audible effect and is what happens when you're nearing a system's maximum limit. It is all about compromise here. It is a trade-off between having clear sound and having loud sound. Given the same amplification stage, a designer has to make a decision and that's usually done according to the consumer demand and the focusing to certain market. Very few laptops (if any) are focused to audio use and I'm pretty sure they would count on an external audio interface to do all the A/D and D/A conversion.
A way to remedy this would be to use an external sound system. There's nothing wrong with the analogue signal coming out of your laptop, tablet or phone audio out in terms of the factors mentioned above as long as it's for non-professional use.
If you're still not happy with the quality, you could also benefit from an external audio interface. Both tablets and laptops have USB ports so I would look at USB audio interfaces first. [1]: https://en.wikipedia.org/wiki/Frequency_response [2]: https://en.wikipedia.org/wiki/Transient_response [3]: https://en.wikipedia.org/wiki/Signal-to-noise_ratio [4]: https://en.wikipedia.org/wiki/Total_harmonic_distortion