Praise be to Allah.
It is permissible to sell products with a warranty for a specific length of time, and this comes under the heading of a promise or stipulating a benefit for the purchaser, both of which are permissible. Please see: al-Hawaafiz at-Tijaariyyah by Dr. Khaalid al-Muslih, p. 246
It is also permissible to increase the price of the product in return for an increase in the length of the warranty, as we shall see below in the fatwa of Shaykh Ibn Jibreen, may Allah have mercy on him.
With regard to selling separate warranty coverage, such as if a person buys a product without a warranty, or he buys it with a warranty that has ended, so he buys a warranty for another period, this is not permissible, because this involves ambiguity and gambling. In this case he pays money for which he may or may not benefit from coverage. This comes under the heading of gambling, which is haraam, and it is the principle on which commercial insurance is based.
Shaykh Ibn Jibreen (may Allah have mercy on him) was asked: What is the ruling on raising the price of a product in return for an extended warranty period?
He replied: There is nothing wrong with that if it is agreed upon mutually. … As for selling separate warranty coverage, that is not permissible. And Allah knows best.
See also question no. 6249
The difference between increasing the price of the product in return for extending the warranty, and purchasing separate coverage, is that the warranty in the first instance is connected to the sale transaction, and the basic principle is that things may be overlooked if they are connected to (and secondary to) a transaction in a way that is not applicable in other cases.
Hence the scholars have stated that the ambiguity that is prohibited is that which is which has to do with the item that is the main subject of the transaction, not things that are connected to (and secondary to) that item.
It says in al-Ma‘aayeer ash-Shar‘iyyah: If the ambiguity has to do with the item that is the main subject of the transaction, such as selling crops before they ripen – as opposed to selling the trees themselves – in that case the transaction is invalid. But if the ambiguity has to do with things that are connected to (and secondary to) the item that is the main subject of the transaction, then it does not affect the transaction, such as selling of the trees with the crops before they ripen, or selling something that has not yet grown along with that which is already there (in the case of crops), or selling the foetus along with the ewe, or selling the milk in the udder along with the ewe – in all these cases, the ambiguity of all of these (secondary) things may be overlooked and it does not affect the transaction.
And Allah knows best.