If someone caught prayer just before the finishing of second salam (Assalamu Alaykum Wa Rahmatullah)before the saying of Rahmatullah if someone caught prayer will ones salat be valid
The first salam already ends the prayer this is the view of the majority of scholars! In the maliki school of fiqh the Imam even only does (or is asked to do) one salam (see here)!
Some details on the main opinions in each madhab:
Hanafi: say that saying taslim is sunnah not wajib.
Note: this is based on the statement of the fatwa, the technical term of hanafi scholar is that it is wajib but not fardh (ordered) which in the view of other madhabs makes it more or less sunnah like. Abu Hanifa even said that if a person performs tashahud with the Imam and stands up without salam and left the prayer would be valid or at least can be corrected or adjusted by sujud sahw. All other madhabs would consider such a prayer as invalid
محمد ، قال : أخبرنا أبو حنيفة ، عن حماد ، عن إبراهيم في الرجل يجلس خلف الإمام قدر التشهد ثم ينصرف قبل أن يسلم، قال يجزيه، وقال عطاء بن أبي رباح: إذا جلس قدر التشهد أجزأه، قال أبو حنيفة: قولي هو قول عطاء ثم قال محمد: وبقول عطاء نأخذ نحن أيضا
--- (my own translation take it carefully)---
Muhammad said: Abu Hanifa narrated (or informed us) from Hammad from Ibrahim saying: On a Man who sat behind the Imam for the time needed to perform tashahud then left before performing salam. Hammad said: his prayer would be valid. 'Ata' ibn abi Rabah also said: If he sat for the duration of tashhud it would be valid. Abu Hanif : said my opinion on the matter is the one of 'Ata! then Muhammad said: And we also approve the opinion of 'Ata' (This was compiled by Muhammad ibn al-Hassan in his "al-Aathaar الآثار" see #182 here)
Here a quote from bad'i as-sna'i of al-Kassani about the differences between hanfi, maliki and shafi'i view on the matter (taken from this fatwa in Arabic):
قال الكاساني في بدائع الصنائع: لفظة السلام ليست بفرض عندنا ولكنها واجبة, ومن المشايخ من أطلق اسم السنة عليها وأنها لا تنافي الوجوب لما عرف, وعند مالك والشافعي فرض حتى لو تركها عامدا كان مسيئا ولو تركها ساهيا يلزمه سجود لسهو عندنا, وعندهما لو تركها تفسد صلاته.
--- (My own translation take it carefully)---
Al-Kassani said in his bada'i as-snaa'i: The words of as-Salam are not fard (obligatory) in our opinion (school of fiqh), but we consider it wajib, and among our Scholars (or Shouyoukh ) there are whom who called it sunnah and said it is not disproving the wajib of what is known. Malik and a-Shafi'i consider it fard so if somebody left it intentionally he would sin and if he left it unintentionally he is asked to perform sujud shaw in our opinion, but in their opinion his prayer would be considered invalid! (see also in بدائع الصنائع في ترتيب الشرائع)
Also note that abu Hanafi allowed performing taslim (saying it) at the same time the Imam does it while his students rejected it and followed the majority in saying it after the Imam.
Maliki: say that the first taslim is ordered!
Shafi'i: Say the first taslim is wajib (ordered) and the second is mustahab.
Hanbali: Have two major views the first is the same as the shafi'i school (as ibn Qudamah stated) and the second view of later hanbalis is that both taslmis are rukn (ordered) (See this fatwa, note that the mufti and the supervisor of that fatwa site are hanbali or salafi).
And the proof for the necessity of only one taslim are the ahadith quoted in the linked post especially the one of 'Aisha! And the fact that it was a well known sunnah of the muhajireen is even approved by salafi or hanbali scholars as you may read there.
Therefore if you joined a congregation later it is recommended to wait until the Imam performs the second taslim.
See also this fatwa in Arabic (with details on the madhab views) and this in English .
To answer your last comment: As said in the hadith i posted answering your other question one should join Jama'a (congregation) as soon as one can especially if they are sitting or performing sujud, but without hast or hurry as this is prohibited because of the sahih hadith narrated by sahaba like Qatadah and abu Huraaira. Whether you missed thawab al-Jama'a practically yes, but you had the intention to so you may be rewarded for that. And Of course as you missed a whole prayer you may pray it from the beginning, as if you joined after it the ruku'!
But In your case as you came at the 2nd salam, which means you didn't join the congregation and therefore you can't build on the parts of the prayer you did with them. You need to start (a new prayer) by iqama or at least takbirat al-Ehram (takbira to start) as you didn't join the jama'a as they were praying. Maybe you should even wait for others who come late to pray in congregation with them and earn some rewards from that.
Some more details:
If you entered a mosque and the Imam was sitting for the last tashahud if you joined the congregation before the (first) taslim shafi'i and most hanbali would say that you have got the reward for jama'a while maliki and ibn Taymiyyah say if one didn't perform at least one rak'a (starting at least with ruku'u) you won't have been considered to have joined the congregation. Ibn 'Othaymeen even went so far to say that a person whom missed the prayer or joined it after the last ruku'u even should wait for a new jama'a to pray in congregation if he expected that according this Arabic fatwa.
I'd like to say that the statements of ibn Taymiyyah, ibn 'Othaymeen and the malikis must be taken carefully: As yes in this case once the Imam did both taslims you'll have to make up the whole prayer, but that isn't a qualification on whether you missed or got the rewards of the prayer in congregation as Allah only knows your intention and what made you come late. Also read this hadith qualified as hassan.