The Sten gun was almost an improvised weapon. The Brits used it to replace the Lee-Enfield rifles left in Dunkirk.
Not true. The Sten was developed because the British desperatly needed a sub-machine gun. The other options out there had their own difficulties, the Thompson was expensive and supply from the USA was limited and slow, the Lanchester was also slow to produce due to its high quality.
The Sten is more or less a stripped down version of the Lanchester, designed to be manufactured very quickly and cheaply and therefore would be available in large numbers should an invasion happen.
It was never intended to replace the Lee Enfield, not even in the short term. While many weapons were lost at Dunkirk the British had large stores of older versions which were available for issue until replacements could be obtained.
As for its reliability, it wasnt really any worse than many other sub-machine guns of the time. Had it been as bad as some people are making out then there is no way that over 4 million of them would have been issued in the UK alone! And thats not counting the other countries that manufactured their own.