This is a good question. In short, While DJI drones certainly have a lot of engineering and design put into them, the way they achieve long flight times is no secret. The DJI drones' long flight times are largely due to the high capacity batteries, motors, and propellers used. Although, there are many smaller things that also affect flight times.
Probably the most significant of these is the battery. A typical "FPV drone" uses a LiPo battery with a relatively low capacity and relatively low-quality cells in order to reduce the all-up-weight and cost. DJI uses more expensive LiPo cells that have a higher energy capacity per weight. The DJI batteries have noticeably more capacity, but they are heavier and quite expensive making them less than desirable for usual FPV flights because batteries are often destroyed in a crash. However, you certainly could use these very high quality battery cells on an FPV drone if you wanted longer flights. Another way that some FPV pilots can get longer flights without spending too much is by using Li-ion battery packs. They cannot deliver nearly as much current nor are they as durable, but they store a lot of energy and normally can get 20-30 minutes of flight time.
There are many FPV pilots who custom build Li-ion packs out of 18650 cells or buy pre-built Li-ion packs to get longer flight times. One FPV drone I can think of that works well with Li-ion is the Flywoo Explorer LR. I've seen people getting ~40 minutes of flight time with it.
Other big things that contribute to the DJI drones' long flight times is the type of motors and propellers used. Drones that are designed for long flight times, like DJI drones, or some long range FPV drones, have motors with less powerful magnets or a wider air gap between the stator and magnets which results in more energy efficient operation. High performance motors, which are seen on most FPV drones, have very powerful magnets and tiny air gaps to increase performance and torque at the expense of some efficiency. As for propellers, when you look at drones designed for long flight time, you see two blades, low pitch, and longer blades. But when you look at High performance FPV drones, you see steeper pitch, more (usually three) blades, and shorter blades so that the motors can change the prop speed faster. More blades on a propeller usually decreases efficiency but increases stability. Having blades with higher pitch increases the consumption of current, so a lower pitch is often more energy-efficient. And the size of propeller also makes a significant impact as larger propellers are more efficient.
There are a lot of factors that impact the flight time of drones. Certain drones, like the DJI drones, are just designed with efficiency in mind while other drones, like a typical "FPV drone", are designed with performance in mind.