Why do psql queries take longer when inserting many rows. Why is it non linear
Leaving aside the fact that the DISTINCT is causing some weird behavior, there are two main reasons why insert times get longer as bulk loads get larger:


B-tree indexes get less efficient to update as they get larger and have more tree levels.  So indexes take longer to insert a the millionth value than they did the 10th.
At certain sizes, you exceed certain thresholds which cause extra IO on the system, resulting in lag while the IO takes place.  These thresholds, which interact in complex ways, include:

the size of the WAL, causing log rotation
the size of the RAID cache, dropping to disk speeds
the size of Postgres' dedicated cache, causing flushing to the FS
the size of the FS cache's dirty block flushing threshold
the size of the entire FS cache, causing emergency flushing