When you type your password to install a program, your password is read by sudo under the hood. Sudo is a privileged program that runs other programs as root, but it only accepts to do so when called by users who have been authorized to do this. Such users are commonly known as “sudoers”. The Ubuntu installation program creates a first user account and makes it a sudoer. You can configure other accounts to be sudoers by granting them administrator privileges in the user administration GUI.
Sudo asks for your password to confirm that it's you at the keyboard. This has two benefits: someone walking by while your back is turned won't be able to perform administration tasks, and you get some user interface feedback that you're about to change your system configuration.
Sudo runs the installer program as root. This does not mean that the program will run as root. All normal program installation is performed by root, because only root can write to the system directories and modify the database of installed packages. With very few exceptions (setuid or setgid programs), when you run the program, it runs with exactly the same privileges you already have — because “your privileges” actually means “the privileges of the processes that are running in your session”.
By default, Ubuntu does not set a password for the root account. This is more a matter of usability than security. The main benefit of not having a separate password is that users don't have to remember multiple passwords.
Setting a password for the root account does not have any benefit to protect against malware. If you have malware on your machine, it can snoop on everything you do, including typing your password. It can even spoof a password prompt. It doesn't matter whether you end up typing your account's password or the root password: once malware is running on your machine, you've lost: it isn't your machine anymore but the attacker's.
Fortunately, under Linux, it is fairly easy to remain free from malware. Stick to programs that are provided by your distribution. Ubuntu has an extensive collection, so there aren't many tasks that require getting software from other sources. These programs get scrutiny from a lot of people, and if one is ever discovered to contain malware or to have a security vulnerability, this will be promptly fixed in a security update.