The Prophet (may Allah's peace and blessings be upon him) informs that whoever imitates some people - disbelievers, sinners, or righteous - by engaging in any of their peculiar traits, such as their creeds, acts of worship, or habits, becomes one of them. This is because outward imitation of them leads to inward imitation. In fact, imitation of any people indicates admiration of them, and it may result in loving, respecting, and inclining toward them, which may also prompt a person to even imitate them inwardly and in their worship - Allah forbid.
Lessons
We are warned of imitating disbelievers and wicked people.
We are urged to imitate the righteous and follow in their footsteps.
Outward imitation brings about inward love.
A person will be sinful and worthy of punishment in accordance with the type and degree of his imitation of them.
The prohibition regarding the imitation of the disbelievers pertains to their religion and peculiar habits. Other things, like learning professions and so on, do not fall under this prohibition.
Explanation in Arabic
يُخْبِرُ النبيُّ صلى الله عليه وسلم أنَّ مَن تَشَبَّهَ بقومٍ من الكفارِ أو الفُسَّاق أو الصالحين -وذلك بأنْ يَفعَلَ شيئًا من خصائصِهم من العقائد أو العبادات أو العادات- فهو منهم؛ لأنَّ التَّشَبُّهَ بهم في الظاهر يؤدِّي إلى التشبه بهم في الباطن، ولا شك أنَّ التشبهَ بالقوم ناتجٌ عن إعجاب، وقد يؤدِّي إلى محبتهم وتعظيمهم والركون إليهم، وهذا قد يَجرُّ المرءَ إلى أنْ يتشبه بهم حتى في الباطن والعبادة -والعياذ بالله-.
التحذير من التشبُّه بالكفار والفساق.
الحث على التشبه بالصالحين والاقتداء بهم.
التشبه في الظاهر يورث المحبة في الباطن.
يَنالُ الإنسان من الوعيد والإثم بحسب التشبه ونوعه.
النهي عن التشبه بالكفار في دينهم وفي عاداتهم المختصة بهم، أما ما لم يكن كذلك كتعلُّم الصناعات ونحوها فلا يدخل في النهي.