I suspect the payload object is being destroyed by reference somewhere further down your flow.
This works...
[{"id":"226f9f18a6afc487","type":"function","z":"553814a2.1248ec","name":"Payload recorder","func":"\nlet recording = context.get(\"recording\") || false;//get logging recording\n\nif (msg.topic == \"start\") {\n context.set(\"recording\", true);\n context.set(\"measures\", []);\n node.status({fill:\"green\",shape:\"ring\",text:\"Recording\"});\n return [null, null];//no output\n}\n\nif (msg.topic == \"stop\") {\n context.set(\"recording\", false);\n msg.payload = [...context.get(\"measures\") || []];\n context.set(\"measures\", null);\n node.status({ fill: \"red\", shape: \"ring\", text: \"Stopped\" });\n return [null, msg];//pass recorded data out of pin 2\n}\n\nif (recording) {\n const measures = context.get(\"measures\") || [];\n const o = {\n payload: msg.payload,\n topic: msg.topic,\n timestamp: Date.now()\n }\n measures.push(o);\n context.set(\"measures\", measures);\n return [msg, null];//pass msg on to next node\n}\n","outputs":2,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\nlet recording = context.get(\"recording\") || false\nif (recording) {\n node.status({ fill: \"green\", shape: \"ring\", text: \"Recording\" });\n} else {\n node.status({ fill: \"red\", shape: \"ring\", text: \"Stopped\" });\n}","finalize":"","libs":[],"x":2090,"y":460,"wires":[["5999900b2df185a4"],["e6140c609f34d805"]]},{"id":"5999900b2df185a4","type":"debug","z":"553814a2.1248ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2290,"y":420,"wires":[]},{"id":"0f206903f17e01f9","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"livingroom/switch/1","payload":"1","payloadType":"num","x":1810,"y":500,"wires":[["226f9f18a6afc487"]]},{"id":"08c8d12fc86a3f32","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"livingroom/switch/1","payload":"0","payloadType":"num","x":1810,"y":460,"wires":[["226f9f18a6afc487"]]},{"id":"e6140c609f34d805","type":"debug","z":"553814a2.1248ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2290,"y":500,"wires":[]},{"id":"8b336f39bb3cdd09","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bedroom/temperature","payload":"22.2","payloadType":"num","x":1830,"y":540,"wires":[["226f9f18a6afc487"]]},{"id":"9b5e4af82c56b7c9","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"start","x":1870,"y":360,"wires":[["226f9f18a6afc487"]]},{"id":"0fc71aab7e1b81da","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stop","x":1870,"y":400,"wires":[["226f9f18a6afc487"]]},{"id":"1dfff66dc2c243ba","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bedroom/temperature","payload":"22.4","payloadType":"num","x":1830,"y":580,"wires":[["226f9f18a6afc487"]]}]
Output showing payload topic and a timestamp were saved & sent when stopped...