The legislation arose after Robert F. Kennedy Jr.’s failed attempts to get off the presidential ballot in 2024.