Permissible Kinds of Joking in Islam
Question

I saw in one of your answers that joking is permissible if it is true. Can you explain that by giving some examples? Is it permissible to joke by saying mocking words, such as when through his tone of voice, a person indicates that what he means is something other than what he is saying? Is it permissible to tell jokes that are based on imaginary situations?
Praise be to Allah.Is lying prohibited in Islam?
It is well known and established among all Muslims that lying is prohibited in all cases ; in fact, the reprehensible nature of telling lies and the prohibition thereon is something on which all religions agree, and the aversion to lying is something that is deeply rooted in sound human nature, no matter what religion a person follows.
What is required of the Muslim is to be truthful in his speech in all situations.
Allah, may He be Exalted, says (interpretation of the meaning):
{O you who have believed, fear Allah and be with those who are true.} [At-Tawbah 9:119]
`Abdullah ibn Mas`ud (may Allah be pleased with him) narrated that the Prophet (blessings and peace of Allah be upon him) said: “Truthfulness leads to righteousness, and righteousness leads to Paradise. A man may continue to speak the truth until he is recorded with Allah as a speaker of truth. Lying leads to wickedness and wickedness leads to Hell. A man may continue to tell lies until he is recorded with Allah as a liar.” (Narrated by Al-Bukhari, 6094 and Muslim, 2607)
`Abdullah ibn `Amr (may Allah be pleased with him) narrated that the Prophet (blessings and peace of Allah be upon him) said: “There are four characteristics, whoever has them all is a pure hypocrite, and whoever has one of them has one of the characteristics of hypocrisy, until he gives it up: when he is entrusted with something, he betrays that trust; when he speaks, he lies; when he makes a covenant, he breaks it; and when he disputes, he resorts to foul speech.” (Narrated by Al-Bukhari, 34 and Muslim, 58)
The prohibition on telling lies when joking
 The prohibition on telling lies when joking is proven in the Sunnah:
Bahz ibn Hakim (may Allah have mercy on him) said: My father told me that his father said: I heard the Messenger of Allah (blessings and peace of Allah be upon him) say: “Woe to the one who speaks and tells lies in order to make the people laugh; woe to him, woe to him.” (Narrated by Abu Dawud, 4990; classed as sound by Al-Albani in Sahih Abu Dawud, 4990)
It is also encouraged to refrain from lying when joking:
Abu Umamah (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “I guarantee a palace on the outskirts of Paradise for one who refrains from arguing even if he is in the right, and a house in the middle of Paradise for one who refrains from lying even when he is joking, and a house in the highest part of Paradise for one who makes his attitude good.” (Narrated by Abu Dawud, 4800; classed as sound by Al-Albani in Silsilat Al-Ahadith As-Sahihah, no. 273)
 `Abdullah ibn Mas`ud (may Allah be pleased with him) said: It is not right to lie in earnest or in jest, or for any one of you to promise something to his child then not fulfil that promise. (Narrated by Al-Bukhari in Al-Adab Al-Mufrad, 387)
Kinds of joking in Islam
Joking, whether it is based on truth or lies , has many scenarios:

When the joke is based on truth, and there is no lying involved

The basic principle regarding this kind of joking is that it is permissible, if it is done from time to time and the individual is not joking most of the time, and it does not lead to obvious mischief.
An-Nawawi (may Allah have mercy on him) said:
“The scholars said: The kind of joking that is not allowed is when one goes to extremes in joking and persists in that, for it provokes laughter, leads to hardheartedness, and distracts people from remembering Allah, may He be Exalted, and from focusing on their religious duties. In many cases, it also leads to causing offence and development of grudges, and it undermines dignity and respect. As for joking that is free of such elements, that is what is permissible, and that is what the Messenger of Allah (blessings and peace of Allah be upon him) used to do. He (blessings and peace of Allah be upon him) only used to do that on rare occasions, when it served a purpose, or to comfort the one addressed and put him at ease. There is nothing wrong with that at all; rather it is Sunnah and is encouraged, if it is of this type.” (Al-Adhkar,  p. 377)

When the joke is based on a lie

This type of joking is prohibited, as seen in the Hadith of Bahz ibn Hakim (may Allah have mercy on him) quoted above.
Shaykh Al-Islam Ibn Taymiyah (may Allah have mercy on him) was asked about someone who tells people stories that he has made up, and all of them are lies: is that permissible?
He replied:
“As for the one who tells made-up stories to make people laugh, or for some other purpose, he is disobeying Allah and His Messenger. Bahz ibn Hakim narrated from his father, from his grandfather, from the Prophet (blessings and peace of Allah be upon him), who said: “The one who speaks and tells lies in order to make the people laugh, woe to him, woe to him, then woe to him.” And Ibn Mas`ud (may Allah be pleased with him) said: It is not right to lie in earnest or in jest, or for any one of you to promise something to his child then not fulfil that promise.
If, however, that involves transgression against the Muslim, or it involves saying something that goes against Islamic teachings, then it is more emphatically prohibited. Whatever the case, the one who does that is deserving of Shar`i punishment [at the discretion of the judge] that will deter him from doing it. And Allah knows best.” (Majmu` Al-Fatawa,  32/255-256)
In Fatawa Al-Lajnah Ad-Da’imah (26/52), it says:
Question: If, for example, we tell a lie as a joke, is that prohibited or not?
Answer:
“Yes, it is prohibited. In fact, it is a major sin, even if it is a joke.
And Allah is the source of strength. May Allah send blessings and peace upon our Prophet Muhammad and his family and companions.” (Permanent Committee for Academic Research and Ifta. `Abdullah ibn Qa`ud, `Abdullah ibn Ghadyan, `Abd Al-`Aziz `Afifi, `Abd Al-`Aziz ibn Baz.”

Joking by telling stories, when you are not certain whether they are true, but they could have happened

What appears to be the case, based on the actions of some scholars, is that this type of joking is permissible. In the books of some of the scholars we find some funny stories that are attributed to people who lived centuries before, even though it is difficult to verify the stories. But there is no deliberate intention to tell a lie or to transmit a lie, even if the teller does not make an effort to verify the story and ensure that what he is transmitting is true.
Types of funny stories
Shaykh `Abd Al-Muhsin Az-Zamil (may Allah have mercy on him) said:
“Interesting and funny stories are of three types:

Stories which we know to be true. There is nothing wrong with this type, on condition that the story does not contain any prohibited elements, mocking of others or backbiting. It must be free of these things. If the story is permissible, there are no reservations about it, and if it is something that really happened or is most likely to have happened, there is nothing wrong with that.
Stories which are known to be lies and did not happen. It is not permissible to tell these stories.
Stories regarding which it is not known whether they happened or not. There is nothing wrong with telling these stories.

Hence the Prophet (blessings and peace of Allah be upon him) said: “Narrate from the Children of Israel, with no reservations.” Among the stories that are narrated from them are strange and amazing stories that may have happened, so he told the Muslims to narrate from them, and stated that in some of the stories that are narrated from them there are things that are even more amazing.
Abu Dawud (may Allah have mercy on him) narrated with a good Isnad (chain of narration) that the Prophet (blessings and peace of Allah be upon him) used to narrate stories from the Children of Israel after `Isha’ prayer, and he would not be interrupted for anything except for the obligatory prayer.
This highlights the fact that he (blessings and peace of Allah be upon him) would sometimes address them for a long time after `Isha’ prayer.
As noted above, there is nothing wrong with telling these stories regarding which it is not known whether they happened or not, if they are not known to be lies, as Ibn Kathir and a number of other scholars pointed out.”

Imaginary stories which the listeners know are imaginary and did not really happen

If these entertaining stories are made up and told to serve a purpose, such as using them as a means to teach and educate, and the like, then a number of scholars have issued Fatwas stating that they are permissible.
Shaykh Muhammad Rashid Rida (may Allah have mercy on him) said:
“With regard to these imaginary stories, which are akin to the Maqamat stories [which are written in rhymed prose] written by our earlier scholars, which were read in religious schools and other schools, such as the Maqamat of Al-Badi` and the Maqamat of Al-Hariri… he – i.e., Al-Hariri – said that he did not know any of the scholars of the Ummah in his time who forbade such stories which are made up about animals, such as the book of Kalilah wa Dimnah and the like, because the purpose behind them was beneficial exhortations, and the details of the story are not the main purpose. We have never heard of any scholar after him who forbade reading his Maqamat.” (Fatawa Al-Imam Muhammad Rashid Rida,  3/1091-1092).
Shaykh Ibn `Uthaymin (may Allah have mercy on him) said:
“If someone wants to present an example when telling a story, such as if he says: I am going to tell you of the example of a man who said such and such, or did such and such, and such and such happened, and the outcome was such and such, there is nothing wrong with this, to the extent that one of the scholars said regarding the verse {And present to them an example of two men: We granted to one of them two gardens of grapevines, and We bordered them with palm trees and placed between them [fields of] crops} [Al-Kahf 18:32 – interpretation of the meaning]: This did not really happen, and in the Quran it says: {Allah presents an example: a slave owned by quarrelling partners and another belonging exclusively to one man – are they equal in comparison? Praise be to Allah! But most of them do not know.} [Az-Zumar 39:29 – interpretation of the meaning] So if someone tells a story and does not attribute it to a specific person, but it is as if something happened, and the outcome was such and such, there is nothing wrong with that.
But if he attributes it to someone and it is false, then this is prohibited and is a lie. The same applies if the purpose of telling the story is to make people laugh, because it is narrated from the Prophet (blessings and peace of Allah be upon him) that he said: “Woe to the one who speaks and lies in order to make the people laugh; woe to him, then woe to him.”” (Liqa’ Al-Bab Al-Maftuh, 77/23)
Shaykh Ibn Jibrin (may Allah have mercy on him) was asked:
It is common among some of our brothers to tell interesting stories which involve lies in order to make people laugh, and when we advise them [not to do that], they say: It is permissible to tell interesting stories if it could have happened, even if you do not know whether it actually happened. Is that correct?
He replied:
“The word translated here as “interesting stories” is used to refer to strange stories, and usually they are things that happened, but they could be imaginary. The purpose of that is to present an example, as Al-Hariri did in his Maqamat, and as others did who wrote books containing these interesting stories.
But it is prohibited to tell lies for the purpose of making people laugh. The Prophet (blessings and peace of Allah be upon him) said: “Woe to the one who speaks and tells lies in order to make the people laugh; woe to him, woe to him.”
But if the audience knows that this is an imaginary tale and did not really happen, but it could have happened, so it is a warning against a similar thing that could happen, or it is preparing people for such possible events, then this is permissible. And Allah knows best.”
What may be understood from the Fatwas of Shaykh Ibn `Uthaymin and Shaykh Ibn Jibrin (may Allah have mercy on them both) is that this permissibility is restricted to the kind of imaginary story that is told for a purpose or as a lesson, and is not about a particular person. If the story is made up about a particular person, or is made up just to make people laugh, then that is not permissible.
Among the earlier scholars who held a similar view was Ibn Hajar Al-Haytami Ash-Shafa`i (may Allah have mercy on him), who said:
“An authentic Hadith says: “Narrate from the Children of Israel, with no reservations” and the report which says “Wonders occurred among them” indicate that it is permissible to listen to such wondrous stories for entertainment and not for any other purpose.”
From this it may be understood that it is permissible to listen to strange and wondrous stories, or any stories regarding which we cannot be certain that they are lies, for the purpose of entertainment, and even if it is certain that it is a lie, but the purpose is to give an example, exhort and educate, such as encouragement to be brave in the imaginary words of humans or animals.” (Tuhfat Al-Muhtaj bi Sharh Al-Minhaj,  9/398)

What we understand from what is mentioned in the question – Is it permissible to joke by saying mocking words, such as when through his tone of voice, a person indicates that what he means is something other than what he is saying?  – is that this is referring to when a man says to his friend: Do you have such and such? And the friend answers: No, but from his joking tone of voice, the questioner will understand that what he means is yes.

In this case, if we only focus on the words, then it is a lie, because no is the opposite of yes.
But if we look at what the listener understands from the context, it may not be a lie, because the meaning that the listener understood was correct, and because words may have different meanings depending on the context in which they are said and the way in which they are uttered. So, for example, the phrase “What is this?” is a question, but a person may sometimes say it in a particular tone of voice from which what is understood is amazement or objection, and the like.
Similar to that is what was narrated from ash-Sha`bi (may Allah have mercy on him), that a dull-witted man met ash-Sha`bi and a woman who was walking with him, and he said: Which of you is ash-Sha`bi? He said: She is. The scholars mentioned this story; it was mentioned by Adh-Dhahabi in Siyar A`lam an-Nubala’ (4/311), without comment.
The ruling on this type of story is not clear, and we have not come across any scholarly views concerning it. What is most likely to be the case is that there is a concession allowing this type, especially when there is another strong and clear indication to indicate what is meant, although it would have been better not to narrate the story, so as to avoid a dubious matter. The Prophet (blessings and peace of Allah be upon him) said: “That which is permissible is clear and that which is prohibited is clear, and between them are doubtful matters of which many people are not aware. Whoever guards against the doubtful matters will protect his religious commitment from shortcomings and will protect his honour from slander, but whoever falls into that which is doubtful will fall into that which is prohibited, like a shepherd who grazes his flock around private land; he will soon graze in it…” (Narrated by Al-Bukhari, 52)
And Allah knows best.