I just bought a new LED lamp and, when I turn it on, it slowly turns off in a few seconds. Why does it so that? Is there a way to fix it?
The lamp is defective so return it for a replacement.
If you search on Google for "mainstay LED desk lamp" you will quickly see that this is a relatively inexpensive light and so trying to repair it is next to impractical. A light like this that directly connects to the AC mains:
...will have an electronic circuit board inside that converts the line voltage to the low voltage for the operation of the LED(s). That circuit appears to be bad and I can tell you that they are often really low quality so a faulty one is not surprising.