It is not a requirement for one who takes Al-Shahadatayn (testimony of faith) to have it witnessed, but it is preferred as a form of da'wah (invitation) to others to embrace Islam. There is no verse in the Qur'an or a hadith that stipulates a requirement of witness or any other form of proof or evidence related to the testimony of faith.
The five pillars of Islam are:
- Al-Shahaadatayn (testimony of faith)
- Salah (prayers)
- Zakaah (financial dues)
- Sawm Ramadan (fasting the month of Ramadan)
- Hajj (pilgrimage)
There are numerous hadiths that enumerate the pillars. Here is one example:
بُنِيَ الإِسْلاَمُ عَلَى خَمْسٍ شَهَادَةِ أَنْ لاَ إِلَهَ إِلاَّ اللَّهُ وَأَنَّ مُحَمَّدًا رَسُولُ اللَّهِ، وَإِقَامِ الصَّلاَةِ، وَإِيتَاءِ الزَّكَاةِ، وَالْحَجِّ، وَصَوْمِ رَمَضَانَ
Islam is based on [the following] five [principles]: To testify that none has the right to be worshipped but Allah and Muhammad is Allah's Messenger (ﷺ), to offer the [compulsory congregational] prayers dutifully and perfectly, to pay Zakat [i.e. obligatory charity], to perform Hajj [i.e. Pilgrimage to Mecca], and to observe fast during the month of Ramadan.
— Sahih Al-Bukhari 2/1
None of the hadiths that mention the pillars of Islam necessitate the testimony of faith be witnessed, or be publicly declared at a later stage. In fact, we do have in the Qur'an and hadiths examples of people who took the testimony of faith and kept their faith secret.
The Prophet (ﷺ) ordered Aba Dhar al-Ghifari to keep his Islam a secret in this long hadith:
يَا أَبَا ذَرٍّ اكْتُمْ هَذَا الأَمْرَ، وَارْجِعْ إِلَى بَلَدِكَ، فَإِذَا بَلَغَكَ ظُهُورُنَا فَأَقْبِلْ
O Abu Dhar! Keep your conversion as a secret and return to your town; and when you hear of our victory, return to us.
— Sahih Al-Bukhari 61/32
This hadith shows that one can keep one's Islam a secret if one fears for one's life, or possible harm. Although in this specific hadith, the testimony was witnessed by both the Prophet (ﷺ) and 'Ali ibn Abu-Talib, it is not clearly stated as a requirement.
From the Qur'an, we know about a man (allegedly the cousin of the Pharaoh) who concealed his faith, and the Qur'an described him as a believer, albeit with his faith concealed:
وَقَالَ رَجُلٌ مُؤْمِنٌ مِنْ آلِ فِرْعَوْنَ يَكْتُمُ إِيمَانَهُ أَتَقْتُلُونَ رَجُلًا أَنْ يَقُولَ رَبِّيَ اللَّهُ وَقَدْ جَاءَكُمْ بِالْبَيِّنَاتِ مِنْ رَبِّكُمْ وَإِنْ يَكُ كَاذِبًا فَعَلَيْهِ كَذِبُهُ وَإِنْ يَكُ صَادِقًا يُصِبْكُمْ بَعْضُ الَّذِي يَعِدُكُمْ إِنَّ اللَّهَ لَا يَهْدِي مَنْ هُوَ مُسْرِفٌ كَذَّابٌ
And a believing man from the family of Pharaoh who concealed his faith said, "Do you kill a man [merely] because he says, 'My Lord is Allah ' while he has brought you clear proofs from your Lord? And if he should be lying, then upon him is [the consequence of] his lie; but if he should be truthful, there will strike you some of what he promises you. Indeed, Allah does not guide one who is a transgressor and a liar.
— Qur'an 40:28
Even during the time of the Prophet (ﷺ), there were men and women that embraced Islam and did not publicly declare their faith:
هُمُ الَّذِينَ كَفَرُوا وَصَدُّوكُمْ عَنِ الْمَسْجِدِ الْحَرَامِ وَالْهَدْيَ مَعْكُوفًا أَنْ يَبْلُغَ مَحِلَّهُ وَلَوْلَا رِجَالٌ مُؤْمِنُونَ وَنِسَاءٌ مُؤْمِنَاتٌ لَمْ تَعْلَمُوهُمْ أَنْ تَطَئُوهُمْ فَتُصِيبَكُمْ مِنْهُمْ مَعَرَّةٌ بِغَيْرِ عِلْمٍ لِيُدْخِلَ اللَّهُ فِي رَحْمَتِهِ مَنْ يَشَاءُ لَوْ تَزَيَّلُوا لَعَذَّبْنَا الَّذِينَ كَفَرُوا مِنْهُمْ عَذَابًا أَلِيمًا
They are the ones who disbelieved and obstructed you from al-Masjid al-Haram while the offering was prevented from reaching its place of sacrifice. And if not for believing men and believing women whom you did not know — that you might trample them and there would befall you because of them dishonor without [your] knowledge — [you would have been permitted to enter Makkah]. [This was so] that Allah might admit to His mercy whom He willed. If they had been apart [from them], We would have punished those who disbelieved among them with painful punishment.
— Qur'an 48:25
In the absence of a direct order to have the testimony of faith witnessed, and with the evidence of having incidents of believers during the time of the Prophet (ﷺ) and before having their faith concealed, it can be concluded that witnessing Al-Shahadatayn is not required.