I have heard that Russia has been fighting with the Chechens on and off for about 300 years, occasionally losing control and reconquering. What exactly does Russia have to gain by retaining control of Chechnya, because I am not sure how could Russia be benefited by such a small nation, that is probably a huge economic burden to keep fighting in.
First note that besides Chechnya there are some related and similar peoples in the North Caucasus: Ingushs, Dagestan peoples, Adygh people, Circassians etc. That is Chechnya is only a part of greater North Caucasus community.
The ancient lifestyle of most of these people, and especially, of Chechens was making raids on neighboring settlements, capturing horses, and hostages for a ransom. They had no agriculture and very little husbandry. This was quite intolerable.
But the main reason for capturing this region was, I think, making a tunnel towards Cristian Georgia to help it against Turkey after Georgians appealed to the Russian Tsar for incorporation of their lands into Russian Empire.
Regarding modern times I think the reasons for the first Chechen war were as follows.
The reasons for the second Chechen war were the same but the following reasons added:
It should be noted however that it is quite uncertain to which extent the Chechen population supported separatism. On all elections they voted for a candidate that was supported by the Kremlin. The originator of the secession of Chechnya, president Dudayev was initially supported by anti-Communists who seized power in Moscow in the early 1990s. He was a honored Soviet pilot who participated in the Afghan war and was the only Chechen to become a Soviet general. He then quickly proceeded to install personal dictatorship.
After Dudayev was killed, a new president Maskhadov was elected. He was known for signing a peace treaty with Moscow and was supported by the Russian media in hope he would be a moderate leader. This suggests that the Chechens in general did not want a war. It turned out later that Maskhadov either supported the Jihadists and terrorists or was unable to do anything to control the situation, so the accords he signed were broken.
It's a bit of a long write-up, but the best reason is fairly easy to trace on a map.
The southern border of Russia between Caspian and Black seas is pretty defenseless as far as natural features (same is true for other borders). So historically, Russia worked/fought to extend its borders to defensible ranges, in case of this specific area, the Greater Caucusus Mountains range that extends from around Sochi on Black sea to NorthEast corner of Azerbaijan on Caspian sea.
This is not really an academic exercise, since historically, that region was strongly threatened by fairly expansionist Ottoman Empire and modern day Turkey (see larger Wiki map for good visual). Russia fought a whole bunch of wars with Ottomans/Turks, and given modern geopolitics, is still strongly competing with Turkey, which is on the accendant path in the region/world.
The of course ties into access to Caspian resources, especially oil (notice that if you lose Chechnya, you will possibly lose Dagestan, meaning the whole western Caspian seaboard).
Chechnya contains the oil center known formerly as Grozny. It sits on the road to Derbens, and the rest of Dagestan, as well as Baku in Azerbaijan, which are also major oil producers. The region could become critical in shipping other oil and gas resources from around the Caspian sea, across the Caucasus, to the Black Sea.
Basically, Chechnya is close to Russia's main sources of oil, both for its own use and for export, meaning that a hostile presence there could be economically and strategically threatening.