Republican lawmakers in Montana swiftly approved the measure despite opposition from Democrats who say it will complicate daily life for two lawmakers who are transgender and nonbinary.