For every file format a program meant to process is associated. For e.g a PDF can be processed by a program capable of parsing pdf format. While processing each format, certain parsing and processing of data is involved. Malwares are crafted to exploit the vulnerabilities of these processing programs. By assigning an extension, the file format is easily identified by the OS and corresponding program capable of parsing it is fired up. Thus, vulnerabilities in widely used softwares make the users more vulnerable, like in case of Surtr family of malware exploited the vulnerability in M$ word.
Renaming an extension is a solution only until the corresponding program for which the file is crafted is not launched. For instance, a .pdf malware renamed as .txt is not harmful until the data is processed by a pdf reader (which malware targets).