The expedition of Dhat al-Riqa took place as a consequence of the Banu Ghatafan tribe (and other tribes) who were assembling troops to attack the Muslim community. Hence, the Prophet (p) and his companions prepared for battle against the criminals.
It is claimed by some that there was no evidence of Banu Ghatafan tribe to attack the Muslims. This cannot be true, since in our most authentic reports it mentions that when the Muslims were praying in territory near Dhat al-Riqa, they were afraid they would get attacked. So one group of Muslims prayed prostrating to the ground, while the second group was standing praying having a watchful eye for the enemy.
These authentic reports tell us that the Muslims did indeed know that the enemy was about to attack and kill Muslims, for why would Muslims be afraid of an attack, if as critics claim there was no threat?
This shows the news which Prophet Muhammed (p) received on banu Ghatafan tribe (and other tribes) that they wanted to attack the Muslims was true.
Historical reports on this incident
Narrated Salih bin Khawwat: Concerning those who witnessed the Fear Prayer that was performed in the battle of Dhat-ur-Riqa’ in the company of Allah’s Messenger; One batch lined up behind him while another batch (lined up) facing the enemy.
The Prophet led the batch that was with him in one rak`a, and he stayed in the standing posture while that batch completed their (two rak`at) prayer by themselves and went away, lining in the face of the enemy, while the other batch came and he (i.e. the Prophet) offered his remaining rak`a with them, and then, kept on sitting till they completed their prayer by themselves, and he then finished his prayer with Taslim along with them. (Sahih al-Bukhari Volume 5, Book 59, Hadith 451)
Yazid b. Ruman told on the authority of Salih b. Khawwat on the authority of one who prayed in time of danger with Allah’s Messenger (may peace he upon him) at the Battle of Dhat ar-Riqa’ that a group formed a row and prayed along with him, and a group faced the enemy.
He led the group which was along with him in a rak’ah, then remained standing while they finished the prayer by themselves. Then they departed and formed a row facing the enemy. Then the second group came and he led them in the remaining rak’ah, after which he remained seated while they finished the prayer themselves. He then led them in salutation. (Sahih Muslim Book 4, Hadith 1829)
Narrated Salih b. Khawwat: On the authority of a person who offered the prayer in time of danger along with the Messenger of Allah at the battle of Dhat al-Riqa. One section of people stood in the row of prayer along with the Messenger of Allah and the other section remained standing in front of the enemy.
He led those who were with him in one rak’ah and remained standing (in his place) and they completed (the second rak’ah) by themselves. Then they turned away and arrayed before the enemy.
Thereafter the other section came and he led them in the rak’ah which remained from his prayer. He then remained sitting (in his place) and they completed their one rak’ah by themselves. He then uttered the salutation along with them. Malik said: I like the tradition reported by Yazid b. Ruman (i.e. the present tradition) more than (other versions) I heard. (Sunan Abi Dawud Book 4, Hadith 1234)
It was narrated from Salih bin Khawwat from one who had prayed the fear prayer with the Messenger of Allah on the day of Dhat Ar-Riqa’ that: One group had formed a row behind him and another group faced the enemy. He led those who were with him in praying one rak’ah, then he remained standing and they completed the prayer by themselves.
Then they moved away and formed a row facing the enemy, and the other group came and he led them in praying the rak’ah that was left for him, then he remained sitting while they completed the prayer by themselves, then he said the taslim with them. (Sunan an-Nasa’i volume 2, Book 18, Hadith 1538)
Yahya related to me from Malik from Yazid ibn Ruman from Salih ibn Khawwat from someone who had prayed (the prayer of fear) with the Messenger of Allah, may Allah bless him and grant him peace, on the day of Dhat ar-Riqa that one group had formed a row with him and one group had formed a row opposite the enemy. He then prayed one raka with the group he was with, and then remained standing while they finished by themselves.
They then left and formed a row opposite the enemy, and then the other group came and he prayed the remaining raka of his prayer with them, and then remained sitting while they finished by themselves. Then he said the taslim with them. (Muwatta Malik (The Fear Prayer) Book 11, Hadith 1)
Scholars commenting on this incident
Shaykh Allama Shibli Numani:
By now, the combined intrigues of the Quraish and the Jews had stirred up the whole land from Mecca to Medina. The tribes one and all set about making preparations for an attack on Madina. The Anmar and the Thalaba were the first to move.
The Holy Prophet (p) came to know of it, and on the 10th of Muharram, Hira 5 (June, 626 C.E.), he left Medina with four hundred Companions and reached the place known as Dhat ar-Riqa. Hearing of the approach of the Muslim army the tribesmen fled into the mountains. 
Safi ur Rahman Al Mubarakpuri:
THE EXPEDTION OF DHAT AL-RIQA
The Prophet had barely subdued one set of enemies when the news came that another conglomeration was massing arms against him. The Bediouns of Banu Anmar, Tha’laba and Maharib were preparing to strike and had to be quelled. Uthman bin Affan was given the responsibility of Madinah, and seven hundred men set out with the Prophet.
Their destination was Nakhlah, a two day journey from Madinah. There they encountered warriors from Banu Ghatafan. 
 Sirat -un- Nabi By Shaykh Allama Shibli Numani – Volume 2, page 99
 When The Moon Split (A Biography Of Prophet Muhammed) By Safi ur Rahman Al Mubarakpuri, page 238