Does the Prime Minister always have to listen to their party? Can they say whatever they want?
Role of the Prime Minister in Australia.

Parliamentary Education Office (peo.gov.au)
Description
This graphic shows that the Prime Minister is the most senior minister in the Australian Government as well as being key spokesperson for Australia, the head of Cabinet and the leader of the government.
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
You are free to share – to copy, distribute and transmit the work.
Attribution – you must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
Non-commercial – you may not use this work for commercial purposes.
No derivative works – you may not alter, transform, or build upon this work.
Waiver – any of the above conditions can be waived if you get permission from the copyright holder.
Great question! The Prime Minister is the leader of the party that is in government. The Prime Minister is chosen by their party and can keep their job as long as they are a member of parliament and have the support of the government. Because of this, the Prime Minister will want to work with their party and ensure that what they say has the support of most of the members of the government.
The Prime Minister is also not able to make laws for Australia. The Prime Minister is only one member of parliament. If they want to make a new law, they need to convince their team to vote for the idea.