The core rule is that one fulfills the mitzvah of matzah only with a substance capable of becoming chametz: Shulchan Arukh, Orach Chayim 453:1 and Mishneh Torah, Leavened and Unleavened Bread 6:4 state that matzah must come from one of the five grains—wheat, barley, spelt, oats, and rye—because only these can become chametz, while rice, millet, and other legumes cannot become chametz and therefore cannot be used to fulfill the obligation.
This is rooted in the Gemara's own drashah: Pesachim 35a:6-7 derives from the pasuk 'lo tochal alav chametz... matzot tochal alav' (Shemot 12:15-20) that only things which can come to a state of chametz can be used for the mitzvah of matzah, excluding rice and millet which at most reach a state of spoilage, not chametz; Mishneh Torah, Leavened and Unleavened Bread 5:1 and Tur, Orach Chayim 453 likewise confine the prohibition of chametz on Pesach to these same five grains, and Shulchan Arukh HaRav, Orach Chayim 453:1 and Mishnah Berurah 453:3 restate this principle, with the Mishnah Berurah noting that even rice flour kneaded with hot water and swelling like risen dough is not chametz but mere spoilage, and is permitted to eat.
The flip side of this principle — that the five grains themselves do not become chametz through every liquid — is drawn out by the Gemara's teaching that fruit juice does not cause dough to become chametz (Pesachim 35b:1), so dough kneaded in wine, oil, honey, or similar liquids is not full-fledged chametz, though Pesachim 36a:5 records that such 'rich dough' is also excluded from fulfilling the matzah obligation because it is not 'lechem oni.' Rav Eliezer Melamed (Peninei Halakhah, Pesach 8:1) confirms that fruit juice (mei peirot) does not produce chametz, so dough kneaded with it may be eaten on Pesach but cannot be used for the mitzvah of matzah on the first night.
Other sugyot in Pesachim extend the same capacity-to-become-chametz analysis to various cases: Pesachim 40a:14-16 discusses the mitzvah to soak and guard the grain from the earliest stage so that it does not become chametz; Pesachim 40b:6 discusses adding flour to a pot with vinegar to prevent it from becoming chametz; Pesachim 39b:12-13 lists foods that, having already been baked, boiled, or scalded, can no longer come to a state of chametz; and Pesachim 114b:9 notes Rabbi Yochanan ben Nuri's own minority view that rice is a type of grain capable of chametz and karet, a position not accepted as halacha.
Once matzah has been fully baked, its capacity to become chametz is already spent, as Rav Eliezer Melamed (Peninei Halakhah, Pesach 8:2) explains: fully baked matzah, identified by its crust and clean break, cannot become chametz even when soaked in water or ground into flour and re-kneaded, which is why it may be soaked in soup or used for kneidlach.
Avnei Yashfeh 2:47 addresses the related concern that dough cannot suddenly become chametz, holding that because the precise time limit for chametz formation is uncertain, one must hasten the preparation of matzah as much as possible, and also treats the question of not using a previously-returned matzah for the mitzvah of matzah.
Several other sugyot touch on adjacent aspects of the five-grain/chametz-capacity framework without altering it: Berakhot 38b:7-8 discusses whether one fulfills the matzah obligation with a soaked or boiled wafer; Pesachim 120:4-5 discusses eating sweet cakes before the required olive-bulk of matzah; Pesachim 39a:11-12 derives the parallel requirement that maror be a vegetable like matzah is a plant; Mishneh Torah, Leavened and Unleavened Bread 6:8 requires that valid matzah be fit to be eaten in all dwelling places; and Shulchan Arukh, Orach Chayim 208:2 and Arukh HaShulchan, Orach Chaim 208:9 discuss the brachot on dishes made from the five grains mixed with other ingredients, while Gevurot Hashem 36:2 and Sfas Emes al HaShas, Pesachim 35b and Sfas Emes al HaShas, Pesachim 35a further elaborate on the theme of dough not having had time to become chametz and the halachic texture of the rice/chametz question.