In order to answer this question, one must understand how TCP/IP connections are made.
Data is not just sent continuously as one would think happens. There is also a control mechanism to know if the data actually came through.
In order to make this happen, the communication goes as follows: Server sends data in chunks and the client acknowledges the data by replying how much data it received.
In order for the server to know how much data it can send it will send the data as follows:
First 1 byte of data is sent, client replies: 1.
Then 2 bytes are send, client replies: 2
then 4 bytes are send, then 8, then 16, then 32, and the amount of data is increased exponentially.
When a line is unstable, the client may not receive all data and thus replies with an incorrect number.
For example, the server sent 4096 bytes of data, but the client received 3165. The server knows something went wrong and will ignore the last transfer, and starts resending the last 4096 bytes. But instead of sending it all 4096 again, it starts sending 1, then 2, then 4, then 8, etc...
The server also measures how long it takes for each datachunk to be sent and received, and when the server notices it takes considerably longer to get that reply, even though the correct amount of data was returned, it knows a speed limit has been reached, and will keep sending that amount of data, not go higher. This strategy results in the most optimal data transfer.
If a connection is unstable, but only one connection is made, the amount of data is going to be higher because one connection of 1 megabit will have more data per chunk than multiple simultanious connections over 1 megabit. If there are 4 connections at the same time, each chunk is 1/4th of a megabit in size. Smaller chun sizes mean there is less likely a problem with an unstable connection, and given that an unstable connection will reset the transfer rate to 0 in order to try again, if 1 of 4 connections is reset, the remaining 3 keep their full speed and may even increase a bit to compensate.
Given that nowadays when you connect to a server on the internet, you almost always do so with multiple connections, if speedtest only did one connection, an unstable connection would not show the right data compared to actual results.
Keep in mind, that with fast internet speeds, these speed resets happen so quickly that you don't see the graph represented to dip down all the way to 0 unless there is much data corruption in series so the speed crawls down to very low speeds.
So TL;DR: An unstable connection will cause a situation where, if incorrect received bytes are returned, the connection speed is reset which gives a very distorted image in a speedtest.